09-24-04 07:48 AM
Hi Dune,
here is some code that shows how to create a template definition with a
placeholder definition programmatically.
It also shows how the proeprties of the placeholder definition are set.
// Get the CMS application context
CmsApplicationContext cmsContext = new CmsApplicationContext();
// Make sure to set the context to be in the Update mode (which means you
can write
// back to CMS using PAPI.
cmsContext. AuthenticateAsCurrentUser(PublishingMode
.Update);
TemplateGallery tplGallery = cmsContext.RootTemplateGallery;
// template stuff
Template newTemplate = tplGallery.CreateTemplate();
newTemplate.SourceFile = "/Test/MyTemplate.aspx" ;
newTemplate.Name = "MyTemplate";
// Create new HtmlPlaceholder Definition in the Template
HtmlPlaceholderDefinition phDef =
newTemplate.CreatePlaceholderDefinition( new HtmlPlaceholderDefinition() )
as HtmlPlaceholderDefinition;
phDef.Name = "MyPhDef";
phDef.AllowAttachments = true;
phDef.AllowHyperlinks = false;
phDef.AllowLineBreaks = false;
phDef.Formatting =
HtmlPlaceholderDefinition.SourceFormatting.FullFormatting;
CustomPropertyDefinition cpDef =
newTemplate.CreateCustomPropertyDefinition();
cmsContext.CommitAll(); // stefang: this commit is required to avoid
duplicate definitions. Bug?
cpDef.Name = "MyCustPropDef" ;
cpDef.DefaultValue = "MyValue" ;
newTemplate.Submit();
// end template stuff
cmsContext.CommitAll() ;
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
MCMS FAQ:
http://download.microsoft.com/downl...>
MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...nagement+Server
MCMS Whitepapers and other docs:
http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
--------------------------------
"Dune" <Dune@discussions.microsoft.com> wrote in message
news:90614490-A554-4F30-AA83-076D6CCA702D@microsoft.com...
> How can I set the properties for a placeholder definition through code?
>
> I've created a custom placeholder by inheriting from HtmlPlaceholder but
> would like to restrict the user by setting the properties of the
> PlaceholderDefinition associated with my custom placeholder, that is, I
would
> like to control AllowHyperlinks, AllowLinebreaks, Formatting,
> AllowAttachments etc programmatically.
>
> Cheers
[ Post a follow-up to this message ]
|