文件将母版页从sharepoint主站点复制到sharepoint子站点

时间:2011-09-16 08:11:38

标签: c# visual-studio-2008 sharepoint-2007

我有这个sharepoint主页文件

http://abcd.com/sites/forum/_catalogs/masterpage/MyCustomMasterPage.master

我想将Custom Master Page.master复制到

http://abcd.com/site/forum/MySiteA/_catalogs/masterpage/MyCustomMasterPage.master

我将如何在C#中执行此操作?请帮我。谢谢!

1 个答案:

答案 0 :(得分:1)

string strMPageURL ="http://abcd.com/sites/forum/_catalogs/masterpage/MyCustomMasterPage.master";

SPFolder mPageFolder = spWeb.Folders["_catalogs"].SubFolders["masterpage"];
using (WebClient oWebClient = new WebClient())
{
    SPFileCollection mPageFileCollection = mPageFolder.Files;
    SPFile mPageFile = mPageFileCollection.Add(
        "MyCustomMasterPage.master",
        oWebClient.OpenRead(strMPageURL)
    );
}

它实际上就像您将母版页上传到_catalogs / masterpage文件夹一样,但区别在于它来自网页而不是来自本地机器。

如果您计划上传主页,就像使用本地计算机上传文件时开箱即用的方式一样,您可以这样做。

string strMPageLocation =@"C://MyCustomMasterPage.master";

SPFolder mPageFolder = spWeb.Folders["_catalogs"].SubFolders["masterpage"];
using (FileStream mPageStream = new FileStream(strMPageLocation,FileMode.Open))
{
    SPFileCollection mPageFileCollection = mPageFolder.Files;
    SPFile mPageFile = mPageFileCollection.Add(
        "MyCustomMasterPage.master",
        mPageStream
    );
}