编程实例在Sharepoint Web部件页 [英] Programmatically instantiate a web part page in Sharepoint

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

问题描述

有没有一种简单的方法来Web部件页添加到SharePoint网站的编程方式,即使用对象模型或Web服务?它似乎直截了当创建列表,并以这种方式添加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 Files\Common
Files\Microsoft Shared\web服务器
extensions\12\TEMPLATE\1033 \STS\DOCTEMP\SMARTPGS

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS

然后设置一个流模板,并使用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);
}



注意:此方法假定您已经安装了美的SharePoint版本,使用1033语言代码。只要改变如果不同的路径。

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天全站免登陆