在 Sharepoint 中以编程方式实例化 Web 部件页面 [英] Programmatically instantiate a web part page in Sharepoint

查看:17
本文介绍了在 Sharepoint 中以编程方式实例化 Web 部件页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以使用对象模型或 Web 服务以编程方式将 Web 部件页面添加到 Sharepoint 站点?以这种方式创建列表和添加 Web 部件似乎很简单,但我找不到有关如何创建内容页面的示例.

Is there a simple way to add a web part page to a Sharepoint site programmatically, using either the object model or web services? It seems straight-forward to create lists and add web parts in this manner, but I can't find an example of how to create a content page.

对于普通 WSS 安装(不是 MOSS).

For a plain WSS installation (not MOSS).

推荐答案

我将采取的路线是这不是一个协作/发布站点,因为它没有被提及并且 wss 在标签列表中.与使用发布网站相比相当笨重...

I'm going to take the route that this isn't a collaboration/publishing site as this isn't mentioned and wss is in the tag list. Pretty clunky in comparison to using a publishing site...

首先选择您要使用的 Web 部件页面模板:

First choose the web part page template you'd like to use from:

C:Program FilesCommon文件微软共享网络服务器extensions12TEMPLATE1033STSDOCTEMPSMARTPGS

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATE1033STSDOCTEMPSMARTPGS

然后为模板设置流并使用 SPFileCollection.Add() 将其添加到您的文档库中.例如:

Then set up a stream to the template and use SPFileCollection.Add() to add it to your document library. For example:

string newFilename = "newpage.aspx";
string templateFilename = "spstd1.aspx";
string hive = SPUtility.GetGenericSetupPath("TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\");
FileStream stream = new FileStream(hive + templateFilename, FileMode.Open);
using (SPSite site = new SPSite("http://sharepoint"))
using (SPWeb web = site.OpenWeb())
{
    SPFolder libraryFolder = web.GetFolder("Document Library");
    SPFileCollection files = libraryFolder.Files;
    SPFile newFile = files.Add(newFilename, stream);
}

注意:此解决方案假定您已安装使用 1033 语言代码的美国 SharePoint 版本.如果不同,只需更改路径.

Note: This solution assumes you have the US SharePoint version installed that uses the 1033 language code. Just change the path if different.

这篇关于在 Sharepoint 中以编程方式实例化 Web 部件页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆