views:

387

answers:

2

Hi there,

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 all my attempts of setting it's content didn't work, so please help me :-P

Tks,
Pedro José Batista

+4  A: 

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;
Pedrin
+2  A: 

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.

Michael L
I understand that, but given the context of what I'm doing I don't think that the use of a feature is the best option. I'm trying to migrate a standard HTML page to a Publishing page with a console tool and the use of both web parts and custom code is not recommended.
Pedrin