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

本文关键字:站点 sharepoint 复制 主站 文件 母版页 | 更新日期: 2023-09-27 18:08:40

我有一个sharepoint主页文件

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

,我想复制MyCustomMasterPage。主

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

我如何在c#中做到这一点?请帮帮我。谢谢!

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

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
    );
}