Matthew Knott

Previous: Moving A SharePoint Publishing Page To Another Site Collection - Part 2
Next: Querying Sharepoint Events Using SPQuery (CAML)

Setting Page Content In SharePoint 2007 Programattically, And It's Drawbacks

Posted on Monday, 23 February 2009 07:39

I've been working on building Publishing Pages dynamically and one of the things I wanted to do was insert rich text into a SharePoint publishing page. Well, here's how I did it, and also some of the drawbacks I found.

 

SPFile targetFile = myWeb.GetFile(myWeb.ServerRelativeUrl + "/Pages/filename.aspx")
targetFile.CheckOut();
SPField pageContent = targetFile.Item.Fields.GetFieldByInternalName("PublishingPageContent");
targetFile.Item[pageContent.Id] = pageContentString; // Update the list item
targetFile.Item.Update();
targetFile.CheckIn("Checked In");
targetFile.Publish("Published");

This works really well but there are some significant drawbacks you should be aware of. The Page Content field does not allow <object> tags so no flash or embedded movies, and it does not allow relative paths! If you add an <img> tag with a relative path, it will strip the src part alltogether, but leave the remaining code.

Strange but true.

Comments

No comments have been added.

Add a comment