Friday, February 26, 2010

Move Files between SharePoint document library

There are different options to move files between SharePoint document libraries. We can see them one by one.

Option 1 :

We can go to Explorer view, then copy paste the files to different location.


Here we can move multiple files. But Meta data like created by and created time will be changed.


Option 2 :

We can click the file --> Send To --> Other Location

Here Meta data will be retained. But we have to move one by one.

Option 3 :

We can write a C# application.
Add Microsoft.SharePoint.dll in your project.

    using Microsoft.SharePoint;

    private void button1_Click(object sender, EventArgs e)
    {
        SPSite sourceSite = new SPSite(SourceSiteURL);
        SPWeb sourceWeb = sourceSite.OpenWeb();
        SPSite destSite = new SPSite(DestinationSiteURL);
        SPWeb destWeb = destSite.OpenWeb();

        SPFolder oFolder = sourceWeb.GetFolder(SourceFolderName).SubFolders.Folder;
        SPFolder oDestFolder = destWeb.GetFolder(DestinationFolderName).SubFolders.Folder;

        foreach (SPFile oFile in oFolder.Files)
        {
            string strDestURL = oDestFolder.Url + "/";
            SPFile f = oFile;
            f.MoveTo(strDestURL + f.Name);
        }

        sourceWeb.Dispose();
        sourceSite.Dispose();
        destWeb.Dispose();
        destSite.Dispose();
    }


You can customize the code as you need files inside folder or subfolder.
Here we can move multiple files with meta data.

1 comment:

  1. Hello RajaPandian,

    You have more valuable information on your blog.

    Thanks.

    ReplyDelete