|
Home > Archive > Microsoft Content Management Server > October 2005 > script to automatically create pages
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 |
script to automatically create pages
|
|
| drazic19 2005-10-28, 4:58 pm |
| Hi,
Just wondering if its possible to set the CMS to automatically create pages
in each channel. Basically each channel of my site has the same 3 postings
are standard i.e. overview, contacts, events. Instead of having to manually
creating these 3 postings ideally i'd like them automatically created, they
all have a set template and set name so nothing fancy.
Is this possible? if so how?
Thanks,
Michael
| |
| Mei Ying [MVP] 2005-10-28, 4:58 pm |
| Hi
Will this be a one time effort or a daily activity?
If its a one off thing, you could write a console application and use the
API to create the postings. The method that will be of interest is
Channel.CreatePosting().
If its a daily activity, you could create a custom console button that
triggers the creation of the postings.
--
regards
Mei Ying
---
Blog: http://meiyinglim.blogspot.com
Book: http://www.packtpub.com/book/mcms
Contact: meiyinglim@hotmail.com
---
"drazic19" wrote:
> Hi,
>
> Just wondering if its possible to set the CMS to automatically create pages
> in each channel. Basically each channel of my site has the same 3 postings
> are standard i.e. overview, contacts, events. Instead of having to manually
> creating these 3 postings ideally i'd like them automatically created, they
> all have a set template and set name so nothing fancy.
>
> Is this possible? if so how?
>
> Thanks,
>
> Michael
| |
| drazic19 2005-10-28, 4:58 pm |
| Its a one off thing.
So in theory i could write something along the lines of:
For each channel in allChannels
Channel.CreatePosting
Next
Not written a console app for CMS could you recommend somewhere to look at.
Thanks
Michael
"Mei Ying [MVP]" wrote:
[vbcol=seagreen]
> Hi
>
> Will this be a one time effort or a daily activity?
>
> If its a one off thing, you could write a console application and use the
> API to create the postings. The method that will be of interest is
> Channel.CreatePosting().
>
> If its a daily activity, you could create a custom console button that
> triggers the creation of the postings.
>
> --
> regards
> Mei Ying
> ---
> Blog: http://meiyinglim.blogspot.com
> Book: http://www.packtpub.com/book/mcms
> Contact: meiyinglim@hotmail.com
> ---
>
>
> "drazic19" wrote:
>
| |
| Stefan [MSFT] 2005-10-28, 4:58 pm |
| Hi Michael,
below is some code to create a single posting in a console app.
This should give you a good start.
using System;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.Publishing.Extensions.Placeholders;
namespace CreatePosting
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string TemplatePath = "/Templates/Webservice Templates/Automated
Posting";
string ChannelName = "/Channels/stefan/testch";
string PostingName = "SG Test Posting?";
string ImagePath = "/Resources/Automate Gallery/Grizzly.jpg";
string HtmlContent = "Netter Grizzly, oder?";
// Create New CmsApplicationContext
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);
// Retrieve the template with the TemplateName.
Template template = cmsContext.Searches.GetByPath(TemplatePath) as
Template;
if ( template == null )
{
Console.WriteLine("Could not find template " + TemplatePath + ".");
}
// Find the choosen channel to create your posting in.
Channel channel = cmsContext.Searches.GetByPath(ChannelName) as Channel;
if ( channel == null )
{
Console.WriteLine("Could not find channel " + ChannelName + ".");
}
if ( !channel.CanCreatePostings )
{
Console.WriteLine("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(ImagePath) as Resource;
if ( rs == null )
{
Console.WriteLine("Could not find resource " + ImagePath + ".");
}
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();
// Approve if possible.
if (newPosting.CanApprove)
newPosting.Approve();
// Return the GUID of the created posting.
Console.WriteLine("Posting-GUID: "+newPosting.Guid);
}
}
}
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"drazic19" <drazic19@discussions.microsoft.com> wrote in message
news:D871240A-88A4-4B8C-9E23-DAE51A3119A5@microsoft.com...[vbcol=seagreen]
> Its a one off thing.
>
> So in theory i could write something along the lines of:
>
> For each channel in allChannels
> Channel.CreatePosting
> Next
>
> Not written a console app for CMS could you recommend somewhere to look
> at.
>
> Thanks
>
> Michael
>
> "Mei Ying [MVP]" wrote:
>
|
|
|
|
|