As a MCMS 2002 developer it is sometimes hard to get used to the MOSS API for Publishing. I have found that this
Mapping MCMS 2002 APIs to SharePoint Server 2007 site to be very useful. I have supplied some example comparisons from the site below:
|
CmsHttpContext Properties |
SPContext Properties |
| Channel |
PublishingWeb.GetPublishingWeb(SPContext.Current.Web); |
| Posting |
SPContext context = SPContext.Current; PublishingPage currentPage = PublishingPage.GetPublishingPage(context.ListItem); |
| RootChannel |
PublishingWeb.GetPublishingWeb(SPContext.Current.Web.Site.RootWeb); |
| User |
SPContext.Current.Web.CurrentUser |
Getting Posting Values
In MCMS 2002:
Posting p = null;
//Code to get to the posting
AttachmentPlaceholder att = p.Placeholders["attachment1"] as
AttachmentPlaceholder;
String attachmentText = att.AttachmentText;
HtmlPlaceholder html = p.Placeholders["html1"] as HtmlPlaceholder;
String htmlContents = html.Html;
ImagePlaceholder img = p.Placeholders["image1"] as ImagePlaceholder;
String ImageUrl = img.Href;
In SharePoint Server 2007:
PublishingPage p = null;
//Code to get to the page
LinkFieldValue linkfieldValue = p.ListItem["attachment1"]
as LinkFieldValue;
String linkText = null;
if (null != linkfieldValue)
{
linkText = linkfieldValue.Text;
}
String html = p.ListItem["html1"] as string;
ImageFieldValue imagefieldValue = p.ListItem["image1"] as ImageFieldValue;
String ImageUrl = null;
if (null != imagefieldValue)
{
ImageUrl = imagefieldValue.ImageUrl;
}
Setting Postings Values
In MCMS 2002:
Posting p=null;
String text1 = "new attachment text";
String text2 = "new html";
String text3 = "new image href";
//Code to get to the posting
AttachmentPlaceholder att = p.Placeholders["attachment1"] as
AttachmentPlaceholder;
att.AttachmentText = text1;
HtmlPlaceholder html = p.Placeholders["html1"] as HtmlPlaceholder;
html.Html = text2;
ImagePlaceholder img = p.Placeholders["image1"] as ImagePlaceholder;
img.Href = text3;
CmsHttpContext.Current.CommitAll();
In SharePoint Server 2007:
PublishingPage p = null;
String text1 = "new attachment text";
String text2 = "new html";
String text3 = "new image href";
//Code to get to the Page
LinkFieldValue linkfieldValue = p.ListItem["attachment1"] as
LinkFieldValue;
if (null != linkfieldValue)
{
linkfieldValue = new LinkFieldValue();
}
linkfieldValue.Text = text1;
p.ListItem["html1"] = text2;
ImageFieldValue img = p.ListItem["image1"] as ImageFieldValue;
if (null != img)
{
img = new ImageFieldValue();
}
img.ImageUrl = text3;
p.ListItem["image1"] = img;
p.Update();