Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文件将母版页从sharepoint MainSite复制到sharepoint子网站_C#_Visual Studio 2008_Sharepoint 2007 - Fatal编程技术网

C# 文件将母版页从sharepoint MainSite复制到sharepoint子网站

C# 文件将母版页从sharepoint MainSite复制到sharepoint子网站,c#,visual-studio-2008,sharepoint-2007,C#,Visual Studio 2008,Sharepoint 2007,我有这个sharepoint母版页文件 我想把MyCustomMasterPage.master复制到 我将如何在C#中执行此操作?请帮帮我。谢谢 string strMPageURL ="http://abcd.com/sites/forum/_catalogs/masterpage/MyCustomMasterPage.master"; SPFolder mPageFolder = spWeb.Folders["_catalogs"].SubFolders["masterpage"];

我有这个sharepoint母版页文件

我想把MyCustomMasterPage.master复制到

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

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文件夹,但区别在于它来自web而不是本地计算机

如果您计划像从本地机器上传文件一样上传母版页,您可以这样做

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
    );
}
实际上,它的行为类似于将母版页上载到_catalogs/masterpage文件夹,但区别在于它来自web而不是本地计算机

如果您计划像从本地机器上传文件一样上传母版页,您可以这样做

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