1

Using event handlers and workflows I am trying to archive a document library after a certain amount of time has passed. However I am having an issue with moving the document library. This is the code I am using to move the library

SPFolder folder = (SPFolder) properties.Web.GetFileOrFolderObject(source);
folder.CopyTo(dest);
properties.ListItem["Archived"] = "Archived";

I tried to use both copyTo and moveTo but I am getting the same error for both

Microsoft.SharePoint.SPException: 'Error copying folder "/TestArchive". You cannot copy a folder that contains lists, surveys, discussion boards, or document libraries.' COMException: 0x8107096eError copying folder "/TestArchive". You cannot copy a folder that contains lists, surveys, discussion boards, or document libraries.

The library structure looks kind of like this

Archive
------OtherArchiveFiles

TestArchive
-----Docs
--------------TextFiles

And I am trying to get it to be like this

Archive
------OtherArchiveFiles
------TestArchive
--------------Docs
------------------TextFiles

Is there a way to fix this error or do I need to individually move the files in TestArchive into newly created folders in Archive?

EDIT :

So I got it working by individually copying the folders in the doclib to a newly created folder in the Archived Library. Here is my code

SPFolder folderDest = (SPFolder) properties.Web.GetFileOrFolderObject(dst);
SPFolder folderSrc = (SPFolder)properties.Web.GetFileOrFolderObject(source);
folderDest.SubFolders.Add(dest);
folderDest.Update();
foreach (SPFolder folder in folderSrc.SubFolders) {
       if (!folder.Name.Equals("Forms")) {
           folder.MoveTo(dest + "/" + folder.Name);
           folderDest.Update();
       }

}
properties.ListItem["Archived"] = "Archived";
folderSrc.Delete();
folderDest.Update();

However I still want to know if its possible to just move the whole library at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.