locked
I'd like to acquire the version history from a file of a trash can. RRS feed

  • Question

  • I'd like to acquire the version history from a file of a trash can. Is there a good way?

    [premise]
    version management of a document library.
    There is a version history in an eliminated file.
    I don't want to restore a file.

    **[Code No.1]

    //SPWeb.GetFile(strUrl)

    $web = Get-SPWeb("http://server/siteurl/weburl")
    $bin = $web.RecycleBin[0]

    // $bin.DirName, $bin.LeafName

    $file = $web.GetFile("libraryname/filename.xlsx")

    // $file.Exists = false and $file.Versions.Count = 0
    // A SPFile can't be acquired.


    **[Code No.2]

    //SPWeb.GetFile(uniqueId)

    $web = Get-SPWeb("http://server/siteurl/weburl")
    $bin = $web.RecycleBin[0]

    // $bin.ID

    $file = $web.GetFile($bin.ID)

    // $file.Exists = false
    // A SPFile can't be acquired.


    Without restoring a file, can the version history be acquired?
    How is it possible?

    Thursday, September 3, 2015 3:26 AM

Answers

  • Hi,

    The RecycleBinItem class can't provide a method to get the version history.

    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.recyclebinitem.aspx

    As a workaround, we can get all the file versions in Database. The SQL like this:

    select * from [WSS_Content_8080].dbo.AllUserData
    where tp_ListId='1CD81C3E-430A-4E42-ADBF-2CAE68570673' and tp_ID=1
    

    Or you can restore the file and get the version history, then delete the file using code.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Monday, September 14, 2015 1:52 AM
    • Marked as answer by Patrick_Liang Tuesday, September 15, 2015 12:21 PM
    Monday, September 7, 2015 9:23 AM