sharepoint2013 跨站点间copy file

sharepoint提供的spfile相关方法中只能通过站点内复制移动文件,站点间复制文件需要用到将文件转换为字节流数据。以下提供函数进行进行站点间复制参考。

 1  public static void MovetofileAcrossWeb(string sourcewebUrl, string deswebUrl, string sourdocments, string destdocments,string sourfile)
 2         {
 3             using (SPSite site = new SPSite("http://localhost"))
 4             {
 5                 using (SPWeb webb = site.OpenWeb(sourcewebUrl))
 6                 {
 7                     SPFileCollection spfile = webb.GetFolder(sourdocments).Files;
 8 
 9                     using (SPWeb web = site.OpenWeb(deswebUrl))
10                     {
11                         string destinationUrl = destdocments + "/" + spfile[sourfile].Name;//定义源文件位置
12 
13                         SPFileCollection spFiles = web.GetFolder(destdocments).Files;//获取目的文档file集合
14 
15                         byte[] bFile = spfile[sourfile].OpenBinary(); //获取源文件并转化为字节数组
16 
17                         spFiles.Add(destinationUrl, bFile, true);//添加到目的文件夹中,覆盖老版本
18                     }
19 
20 
21                 }
22             }
23         }

 

posted @ 2014-08-15 10:34  瑞灵  阅读(195)  评论(0编辑  收藏  举报