| Author |
Message |
drazic19
Guest
|
Posted:
Thu Oct 27, 2005 12:51 pm Post subject:
script to automatically create pages |
|
|
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 |
|
| Back to top |
|
 |
Mei Ying [MVP]
Guest
|
Posted:
Thu Oct 27, 2005 12:51 pm Post subject:
RE: script to automatically create pages |
|
|
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:
| Quote: | 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 |
|
|
| Back to top |
|
 |
Stefan [MSFT]
Guest
|
Posted:
Thu Oct 27, 2005 12:51 pm Post subject:
Re: script to automatically create pages |
|
|
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...
| Quote: | 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:
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 |
|
|
| Back to top |
|
 |
drazic19
Guest
|
Posted:
Thu Oct 27, 2005 12:51 pm Post subject:
RE: script to automatically create pages |
|
|
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:
| Quote: | 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 |
|
|
| Back to top |
|
 |
|
|
|
|