2013-07-23 46 views
1

我想制作一个程序,将Sharepoint文件夹的所有内容(所有子文件夹和文件)复制到另一个Sharepoint文件夹中。这两个文件夹都将位于同一个Sharepoint站点上。使用Sharepoint复制web服务来复制文件夹和内容

但是,我试图远程做到这一点 - 如果可能的话*。因此,我尝试使用复制Web服务而没有成功。复制Web服务似乎只适用于复制文件,而不是文件夹。另外,我无法确定一种方法来遍历文件夹的内容来复制所有内容 - 它只会复制一个项目。

谢谢你的任何见解或建议,
斯科特

*从一个自定义的CRM工作流活动

~~编辑澄清~~

回答

1

最后,我决定创建我的在SharePoint中拥有自定义Web服务,我可以从Microsoft CRM成功访问。如果有人有兴趣,我贴我用复制的文件夹结构的C#代码:

public String CopyFolderContents(String sourceURL, String folderURL, String destinationURL) 
{ 
    try 
    { 
     #region Copying Code 
     //Get the SPSite and SPWeb from the sourceURL 
     using (SPWeb oWebsite = new SPSite(sourceURL).OpenWeb()) 
     { 
      //Get the parent folder from the folderURL 
      SPFolder oFolder = oWebsite.GetFolder(folderURL); 

      //Create a list of all files (not folders) on the current level 
      SPFileCollection collFile = oFolder.Files; 

      //Copy all files on the current level to the target URL 
      foreach (SPFile oFile in collFile) 
      { 
       oFile.CopyTo(destinationURL + "/" + oFile.Name, true); 
      } 
      //Create a list of all folders on the current level 
      SPFolderCollection collFolder = oFolder.SubFolders; 

      //Copy each of the folders and all of their contents 
      String[] folderURLs = new String[collFolder.Count]; 
      int i = 0; 
      foreach (SPFolder subFolder in collFolder) 
      { 
       folderURLs[i++] = subFolder.Url; 
      } 
      for (i = 0; i < folderURLs.Length; i++) 
      { 
       SPFolder folder = collFolder[folderURLs[i]]; 
       folder.CopyTo(destinationURL + "/" + folder.Name); 
      } 
     } 
     #endregion Copying Code 
    } 
    catch (Exception e) 
    { 
     #region Exception Handling 
     String Message; 
     if (e.InnerException != null) 
      Message = "MESSAGE: " + e.Message + "\n\n" + 
        "INNER EXCEPTION: " + e.InnerException.Message + "\n\n" + 
        "STACK TRACE: " + e.StackTrace + "\n\n" + 
        "Source: " + sourceURL + "\n" + 
        "Folder: " + folderURL + "\n" + 
        "Destination: " + destinationURL; 
     else 
      Message = "MESSAGE: " + e.Message + "\n\n" + 
        "STACK TRACE: " + e.StackTrace + "\n\n" + 
        "Source: " + sourceURL + "\n" + 
        "Folder: " + folderURL + "\n" + 
        "Destination: " + destinationURL; 
     throw new Exception(Message); 
     #endregion Exception Handling 
    } 
    return "Operation Successful!"; 
} 

我所做的只是添加这个方法到SharePoint Web服务,并称之为从CRM和它的作品。

谢谢大家谁提供了其他的答案,
斯科特

-1

有一个简单的解决这个问题,作为其只是复制和粘贴使用简单XCOPY命令

XCOPY复制文件和/或目录树ŧ o另一个文件夹。 XCOPY与COPY命令类似,只是它具有额外的开关来详细指定源和目标。

要将文件夹复制,包括所有子文件夹

XCOPY C:\utils\* D:\Backup\utils /s /i 

这里/我的目标定义为一个文件夹

更多细节请参考this link

+0

有没有办法来触发此从代码中以及在参数传递?这也适用于存储在SharePoint服务器上的文件夹吗? – Scott

+0

不,这完全没有回答你的问题。 –

+0

@ Paul-Jan - 关于应付文件夹的内容?不是吗? – Microtechie