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.