As you all know I write a lot of maintenance console applications to perform upgrades on huge subsets of sites. This week I was asked to create a console application that will cut down six documents libraries into three document libraries. I wanted to use the CopyTo() Function, but there is a bug. I did find a nice MoveTo() Function in SPFile. I ended up using that code instead here is a little sample:
//copy documents and deletes libraries
SPList ProposalsWord = Web.Lists["Proposal Template (Word)"];
foreach (SPListItem Item in ProposalsWord.Items)
{
SPFile File = Web.GetFile(Item.Url);
try
{
File.MoveTo(Web.Url + "/Sample%20Proposals%20PDF/" + Item["Name"].ToString());
}
catch (Exception)
{
}
}
ProposalsWord.Delete();
This piece of code loops through the items on one document library and moves them to another document library. It is fairly simple and straight forward. If you have any comments or questions please let me know.