The main advantage of this code is the use of C#, which means such wonderful features are available as Custom Timer Job, Event Reciever and much more. In my console project I using following reference and code:
using (SPSite SPsite = new SPSite("http://sp/sites/test"))
{
using (SPWeb SPWeb = SPsite.OpenWeb())
{
SPDocumentLibrary srcLib = (SPDocumentLibrary)SPWeb.Lists["Documents"];
SPDocumentLibrary destLib = (SPDocumentLibrary)SPWeb.Lists["OldDocuments"];
foreach (SPListItem sourceItem in srcLib.Folders)
{
SPFolder sourceFolder = sourceItem.Folder;
string targetPath = destLib.RootFolder.ServerRelativeUrl + "/" + sourceFolder.Name;
SPFolder targetFolder = SPWeb.GetFolder(targetPath);
SPListItem targetItem = targetFolder.Item;
sourceItem.Folder.CopyTo(targetPath);
}
}
}
Happy Coding!
No comments:
Post a Comment