MIgrate Documents with is version from SharePoint 2007 to SharePoint 2013 by using C#

Hi,

     I want to migrate a share point document library with its all versions from SharePoint 2007 to SharePoint 2013 programmatically.

 Right now I have created one console application for downloading documents with its version. But I have an issue regrading that I have got current time of that documents during download.

 then I think this would  be move dynamically means, insted of download that documents on local, Directly transfer it on New SharePoint Server.

So,I think It will need Client Object model.

I don't that much of knowledge of client object model in Visual Studio..

I hope,anybody will help me......Thanks in Advance :)

Please see the my following Code....


class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://Site_Name/");
            SPWeb web = site.OpenWeb();
            SPList list =(SPDocumentLibrary) web.Lists[" Library"];
            SPFolder folder = list.RootFolder;
            Program p = new Program();
            p.AccessFolder(folder);
        }

        public void  AccessFolder(SPFolder folder)
        {
            string m_strExportDir=@"C:\Export";
            int iTotalDocs=0;
            string strPath = string.Empty;
            string Pathtofilesystemtosave = @"C:\Export";

           // long lFolderSize = 0;
            int m_iTotalFileVersions = 0;

            if (m_strExportDir != string.Empty)
            {
                strPath = folder.ServerRelativeUrl;
            }

            int iTotalVersions = 0;
            int iI = 0;
            string FinalFileName = "";
            DateTime dt_SPFileCreated = default(DateTime);
            string s_FileName = "";

            foreach (SPFile file in folder.Files)
            {
                iTotalVersions = file.Versions.Count;
                SPFileVersionCollection versions = file.Versions;
                for (iI = 0; iI <= iTotalVersions - 1; iI++)
                {
                    iTotalDocs = iTotalDocs + 1;
                    SPFileVersion version = versions[iI];
                    // Dim hash As System.Collections.Hashtable = _
                    //file.Versions.GetVersionFromID(iI).Properties;
                    // Dim keys As System.Collections.ICollection = hash.Keys
                    System.Collections.Hashtable hash1 = file.Properties;
                    s_FileName = file.Name;
                    dt_SPFileCreated = (DateTime)hash1["vti_timecreated"];
                    m_iTotalFileVersions += 1;
                    FinalFileName = file.Name;
                    System.IO.Directory.CreateDirectory(Pathtofilesystemtosave + "\\Version-" + m_iTotalFileVersions.ToString());
                    string sFileLoc = Pathtofilesystemtosave + "\\Version-" + m_iTotalFileVersions.ToString() + "\\\\" + FinalFileName;
                    byte[] binFile = version.OpenBinary();
                    if (binFile.Length > 0)
                    {
                        FileStream fs = new FileStream(sFileLoc, FileMode.OpenOrCreate, FileAccess.Write);
                        fs.Write(binFile, 0, binFile.Length);
                        fs.Close();
                    }
                }

                // Now for current file
                iI = iI + 1;
                iTotalDocs = iTotalDocs + 1;
                System.Collections.Hashtable hash = file.Properties;
                System.Collections.ICollection keys = hash.Keys;
                s_FileName = file.Name;
                dt_SPFileCreated = file.TimeCreated;

                FinalFileName = file.Name;
                System.IO.Directory.CreateDirectory(Pathtofilesystemtosave + "\\Version-" + iI.ToString());
                string sFileLoct = Pathtofilesystemtosave + "\\Version-" + iI.ToString() + "\\\\" + FinalFileName;
                byte[] binFiles = file.OpenBinary();
                if (binFiles.Length >= 0)
                {
                    FileStream fs = new FileStream(sFileLoct, FileMode.OpenOrCreate, FileAccess.Write);
                    fs.Write(binFiles, 0, binFiles.Length);
                    fs.Close();
                }
            }
            Console.WriteLine("successfully....DOne !!!");


        }

    }

Thanks,

Samadhan Kshirsagar.


May 30th, 2014 6:05am

You can check out my tool at http://gallery.technet.microsoft.com/office/The-Migration-Dragon-for-c0880e59 that leverages the CSOM to upload docs to sps 2013
Free Windows Admin Tool Kit Click here and download it now
May 30th, 2014 6:27am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics