使用C#将文档从SharePoint 2007迁移到SharePoint 2013 [英] Migrate Documents with its versions from SharePoint 2007 to SharePoint 2013 using C#

查看:99
本文介绍了使用C#将文档从SharePoint 2007迁移到SharePoint 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想以编程方式将共享点文档库及其所有版本从SharePoint 2007迁移到SharePoint 2013.



现在我已经创建了一个用于下载文档版本的控制台应用程序。但我有一个问题,即我在下载期间获得了当前时间的文件。



然后我认为这将是动态移动意味着,下载文件时本地,直接在新的SharePoint Server上传输它。



因此,我认为它需要客户端对象模型。



我对Visual Studio中的客户端对象模型知之甚少。



我希望,任何人都会帮助我......谢谢提前:)



请参阅我的以下代码....



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 !!!");


        }

    }



谢谢,



Samadhan Kshirsagar。


Thanks,

Samadhan Kshirsagar.

推荐答案

这篇关于使用C#将文档从SharePoint 2007迁移到SharePoint 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆