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

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

0 comments

Latest Tweets

  • RT @nineplanfailed: New show announced in Cardiff at Tommy's Bar on March 10, 2010 http://lnk.ms/6z2rq

  • Spent 10 minutes on databases and 30 minutes inventing / playing google analytics top trumps

  • Teaching databases to a boy with autism. We're both enjoying.

  • Woo @nineplanfailed just cropped up in my last.fm playlist.

  • RT @RealBillBailey: best film I've seen recently, about a Mongolian horseman who is contemptous of traditional tents, The Yurt Mocker

Follow Me