1

Can anyone point me in the direction of downloading all the versions of a file in a SharePoint 2007 document library?

Is this possible with PowerShell, C#, or another way?

1

You can download the different file versions by keeping the folder structure as well:

private long AccessFolder(SPFolder folder)
{

    string strPath = string.Empty;

    long lFolderSize = 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(iI).Properties();
            // Dim keys As System.Collections.ICollection = hash.Keys
            s_FileName = file.Name;
            dt_SPFileCreated = file.Versions(iI).Created;
            m_iTotalFileVersions += 1;              
            FinalFileName = file.name;
            System.IO.Directory.CreateDirectory(Pathtofilesystemtosave + "\\Revision-" + m_iTotalFileVersions.ToString);
            string sFileLoc = path + "\\Revision-" + 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 + "\\Revision-" + iI.ToString());
        string sFileLoc = Path + "\\Revision-" + iI.ToString() + "\\\\" + FinalFileName;
        byte[] binFile = file.OpenBinary();
        if (binFile.Length >= 0) {
            FileStream fs = new FileStream(sFileLoc, FileMode.OpenOrCreate, FileAccess.Write);
            fs.Write(binFile, 0, binFile.Length);
            fs.Close();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.