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

发布于 2024-12-04 15:30:16 字数 483 浏览 1 评论 0原文

我有这个共享点母版页文件

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

我想将 MyCustomMasterPage.master 复制到

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

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

I have this sharepoint masterpage file

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

and I wanted to copy the MyCustomMasterPage.master to

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

How will I do this in C#? Please help me. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-12-11 15:30:16
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
    );
}
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)
    );
}

It actually behaves like you are uploading the masterpage to the _catalogs/masterpage folder but the difference is that it came from the web not from the local machine.

If you plan to upload the masterpage just like how your out of the box behave using file upload from local machine, you can do this.

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
    );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文