以编程方式设置发布页面内容

时间:2021-12-01 10:55:27

I want to know how to set a Publishing page content through the code (MOSS 2007).
This is how I've created the page:

我想知道如何通过代码设置发布页面内容(MOSS 2007)。这就是我创建页面的方式:

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

但是我设置它内容的所有尝试都没有用,所以请帮助我:-P

Tks,
Pedro José Batista

Tks,PedroJoséBatista

2 个解决方案

#1


5  

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:

我不知道是否可以回答我自己的问题,但在反映了Sharepoint的代码隐藏后,我能够找到一种方法来设置页面的内容:

string content = "Welcome to <strong>My Page</strong>";
page.ListItem[FieldId.PublishingPageContent] = content;

#2


2  

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.

为什么不将代码包装在一个功能中,甚至可以包含物理的aspx文件,但页面内容是可选的。

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.

然后,您可以在激活该功能时将该页面添加到SharePoint附带的标准页面文档库中,这可以通过CAML(XML)完成,您不必在功能接收器中进行编码。

#1


5  

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:

我不知道是否可以回答我自己的问题,但在反映了Sharepoint的代码隐藏后,我能够找到一种方法来设置页面的内容:

string content = "Welcome to <strong>My Page</strong>";
page.ListItem[FieldId.PublishingPageContent] = content;

#2


2  

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.

为什么不将代码包装在一个功能中,甚至可以包含物理的aspx文件,但页面内容是可选的。

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.

然后,您可以在激活该功能时将该页面添加到SharePoint附带的标准页面文档库中,这可以通过CAML(XML)完成,您不必在功能接收器中进行编码。