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 /母版文件夾,但不同的是,它來自於網絡無法從本地機器。
如果您打算上傳主頁面,就像您使用本地計算機上傳文件時的行爲一樣,您可以執行此操作。
string strMPageLocation [email protected]"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
);
}