Microsoft Content Management Server - programmatically set properties

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > September 2004 > programmatically set properties





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author programmatically set properties
Dune

2004-09-23, 5:51 pm

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
Stefan [MSFT]

2004-09-24, 2: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...6a/MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...t+S
erver

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



Dune

2004-09-26, 5:52 pm

Thanks Stefan,

That's exactly what I needed.

Cheers, Dune

"Stefan [MSFT]" wrote:

> 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...6a/MCMS+2002+-+(complete)+FAQ.htm
> MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
> MCMS Sample Code:
> http://www.gotdotnet.com/community/...t+S
erver

> 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...
> would
>
>
>

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com