1

Sharepoint フォルダーのすべてのコンテンツ (すべてのサブフォルダーとファイル) を別の Sharepoint フォルダーにコピーするプログラムを作成しようとしています。これらのフォルダーは両方とも同じ SharePoint サイトにあります。

ただし、可能であれば、これをリモートで実行しようとしています*。そのため、コピー Web サービスを使用してみましたが、成功しませんでした。コピー Web サービスは、フォルダではなく、ファイルのコピーでのみ機能するようです。さらに、フォルダーの内容を反復処理してすべてをコピーする方法を特定できません。1 つのアイテムのみがコピーされます。

洞察やヒントをありがとう、
スコット

*カスタム CRM ワークフロー アクティビティから

~~明確化のために編集~~

4

2 に答える 2

1

最終的に、Microsoft CRM から正常にアクセスできる SharePoint で独自のカスタム Web サービスを作成することにしました。誰かが興味を持っている場合は、フォルダー構造をコピーするために使用した 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 から呼び出すことだけでした。

他の回答を提供してくれたすべての人に感謝します、
スコット

于 2013-08-06T21:09:21.003 に答える
-1

この問題には簡単な解決策があります。単純なXCOPYコマンドを使用してコピー アンド ペーストするだけです。

XCOPYファイルやディレクトリ ツリーを別のフォルダにコピーします。XCOPY は、ソースと宛先の両方を詳細に指定する追加のスイッチがあることを除いて、COPY コマンドに似ています。

すべてのサブフォルダーを含むフォルダーをコピーするには

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

ここで /i は宛先をフォルダーとして定義します

詳細については、このリンクを参照してください

于 2013-07-23T13:58:17.953 に答える