newsgroups-index (beta)

Current group: microsoft.public.cmserver.evaluation

Script for new pages

Script for new pages  
=?Utf-8?B?RGFuaWVsZQ==?=
 Re: Script for new pages  
Stefan [MSFT]
From:=?Utf-8?B?RGFuaWVsZQ==?=
Subject:Script for new pages
Date:Tue, 11 Jan 2005 06:27:02 -0800
Is it possible (and eventually how) to create a script that:
- create a new page with a specific template and in a specific channel
- save the new page
- approve the new page
?

Thanks,
Daniele
From:Stefan [MSFT]
Subject:Re: Script for new pages
Date:Tue, 11 Jan 2005 16:15:28 +0100
Hi Daniele,

something like this:

// Get the CMS application context
CmsApplicationContext cmsContext = new CmsApplicationContext();

// Logon to CMS:
// Assumes that you have Windows Authentication turned on.
cmsContext.AuthenticateAsCurrentUser(PublishingMode.Update);

// Retrieve the template with the TemplateName.
Template template =
cmsContext.RootTemplateGallery.GetByRelativePath(TemplateName) as Template;
if ( template == null )
{
return "Could not find template " + TemplateName + ".";
}

// Find the choosen channel to create your posting in.
Channel channel = cmsContext.RootChannel.GetByRelativePath(ChannelName)
as Channel;
if ( channel == null )
{
return "Could not find channel " + ChannelName + ".";
}

if ( !channel.CanCreatePostings )
{
return "Can not create postings in channel " + channel.Path + ".";
}

// Create a new posting based on the template that you have specified.
Posting newPosting = channel.CreatePosting( template );

// Set the name of the posting.
newPosting.Name = PostingName;

// Set the contents of the ImagePlaceholder Image.
Resource rs = cmsContext.Searches.GetByPath(ImagePathInResourceGallery)
as Resource;
if ( rs == null )
{
return "Could not find resource " + ImagePathInResourceGallery + ".";
}

ImagePlaceholder imgph = newPosting.Placeholders["Image"] as
ImagePlaceholder;
imgph.Src = rs.Url;

// Set the contents of the HtmlPlaceholder ImgDescript.
HtmlPlaceholder htmlph = newPosting.Placeholders["ImgDescript"] as
HtmlPlaceholder;
htmlph.Html = HtmlContent;

newPosting.Submit();

// Do not forget to commit your changes back to CMS.
cmsContext.CommitAll();

// do not forget to dispose the content
cmsContext.Dispose();

// Return the GUID of the created posting.
return newPosting.Guid;

Cheers,
Stefan.

"Daniele" wrote in message
news:938B4791-AE00-41B6-A0ED-1FD3BC2E7E8C@microsoft.com...
> Is it possible (and eventually how) to create a script that:
> - create a new page with a specific template and in a specific channel
> - save the new page
> - approve the new page
> ?
>
> Thanks,
> Daniele
   

Copyright © 2006 newsgroups-index   -   All rights reserved   -   Impressum