使用Sharepoint Copy web服务复制文件夹和内容
本文关键字:文件夹 复制 服务 Sharepoint Copy web 使用 | 更新日期: 2023-09-27 18:24:21
我正在尝试制作一个程序,将Sharepoint文件夹的所有内容(所有子文件夹和文件)复制到另一个Sharepoint文件夹中。这两个文件夹将位于同一Sharepoint网站上。
然而,如果可能的话,我正在尝试远程操作。因此,我尝试过使用Copy web服务,但没有成功。"复制web服务"似乎只用于复制文件,而不用于复制文件夹。此外,我无法确定迭代文件夹内容以复制所有内容的方法——它只复制一项。
感谢您的任何见解或提示,
Scott
*来自自定义CRM工作流活动
~~已编辑以供澄清~~
最后,我决定在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中调用它,它就可以工作了。
感谢所有提供其他答案的人,
Scott
这个问题有一个简单的解决方案,因为它只是使用简单的XCOPY
命令进行复制和粘贴
XCOPY将文件和/或目录树复制到另一个文件夹。XCOPY类似于COPY命令,只是它有额外的开关来详细指定源和目标。
复制包含所有子文件夹的文件夹
XCOPY C:'utils'* D:'Backup'utils /s /i
此处/i将目的地定义为文件夹
有关更多详细信息,请参阅此链接