简体   繁体   English

在SharePoint 2010中以编程方式修改主页的内容

[英]Modify the content of the home page programmatically in SharePoint 2010

First of all, I'm pretty new to SharePoint so don't shoot me if this is a noobish question or if I don't provide all the right information at once... :) 首先,我对SharePoint还很陌生,所以如果这是一个棘手的问题,或者如果我一次也没有提供所有正确的信息,请不要开枪... :)

I have a team-site in SharePoint with following URL: " http://myServer/Opdracht_Ben/ ". 我在SharePoint中有一个团队网站,其网址如下:“ http:// myServer / Opdracht_Ben / ”。 By going to this URL I'm redirected to following page: " http://myServer/sites/Opdracht_Ben/SitePages/Home.aspx ". 通过转到该URL,我将重定向到以下页面:“ http://myServer/sites/Opdracht_Ben/SitePages/Home.aspx ”。

In Visual Studio I have a project for this site with a feature. 在Visual Studio中,我为此站点提供了一个具有功能的项目。 When this site-feature is activated it should change the content of the home-page to some custom tekst and layout (ie: HTML). 激活此站点功能后,应将主页的内容更改为某些自定义tekst和布局(即HTML)。 The content is not contained within a web part or the page is not a WikiPage, just text on a page. 内容不包含在Web部件中,或者页面不是WikiPage,而只是页面上的文本。

I've been looking on MSDN and on several tech-sites and blogs but I have not found anything that could help me further. 我一直在寻找MSDN以及一些技术站点和博客,但没有发现任何可以进一步帮助我的东西。 Does anyone know how I can 'reach' the content of the page and modify/update it? 有谁知道我如何“到达”页面的内容并对其进行修改/更新?

PS: Here on SO I have found a related question ( Click for the question ), but the provided solution is for when the web is a "Publishing Web", which is not the case here, so that solution won't do me any good. PS:在这里,我找到了一个相关的问题( 单击该问题 ),但是提供的解决方案是针对Web是“发布Web”的情况,此处不是这种情况,因此该解决方案对我没有任何帮助好。

Thanks in advance! 提前致谢!

I have found out that the page IS a WikiPage after all. 我发现该页面毕竟是WikiPage。 So I managed to change the content with following code: 因此,我设法通过以下代码更改了内容:

using (var site = new SPSite(ApplicationResources.Url.SiteRoot))
{
    using (var web = site.OpenWeb())
    {
        var page = web.GetFile(ApplicationResources.Url.FullDefaultPageName);
        var item = page.Item;
        item["Wiki Content"] = NewContent(title, text);
        item.Update();
    }
}

Maybe this is not the best method, so if anyone has a better and more reliable solution: feel free to correct me! 也许这不是最好的方法,所以如果有人有更好,更可靠的解决方案:请随时纠正我! ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM