Reputation: 691
I want to know how to set a Publishing page content through the code (MOSS 2007).
This is how I've created the page:
PublishingPage page = publishingWeb.GetPublishingPages().Add("MyPage.aspx", pageLayout);
SPFile pageFile = page.ListItem.File;
page.Title = "My Page";
page.Update();
But my attempts of setting it's content didn't work.
Upvotes: 4
Views: 3158
Reputation: 5690
Personally I think you might be going about it the wrong way.
Why not instead wrap your code in a feature, that could even contain the physical aspx file, having the page content is optional though.
You could then add the page to the standard pages document libary that comes with SharePoint when the feature is activated, this can all be done through CAML (XML), and you should not have to code in a feature reciever.
Upvotes: 2
Reputation: 691
I don't know if it's ok to answer my own question, but after reflecting Sharepoint's codebehind I was able to find a way to set the page's content:
string content = "Welcome to <strong>My Page</strong>";
page.ListItem[FieldId.PublishingPageContent] = content;
Upvotes: 5