Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum How to find location of local path of exported file
    • Sign In

    • State Not Answered
    • Replies 5 replies
    • Subscribers 66 subscribers
    • Views 653 views
    • Users 0 members are here

    How to find location of local path of exported file

    Casper Roubos
    Offline Casper Roubos over 1 year ago

    Hi,

    When I export a file it nicely is shown in the file organizer where it is exported to.

    There is a  [ProjectWiseDocument]$doc0PwObject.CheckedOutLocalFileName, but this remains empty

    How can I find the location to which the file was exported to?

    Thanks in advance.

    • Sign in to reply
    • Cancel
    Parents
    • Kevin van Haaren
      0 Offline Kevin van Haaren Sun, Apr 24 2022 7:59 PM

      Not sure where local document organizer gets the info from but the only way i'm finding to get it is via the document's audit trail.

      (side note: CheckedOutLocalFileName only gets populated when checking out the file with CheckOut-PWDocument. Using Get-PWDocumentsBySearch, including with the -Slow option, will not populate that field even if you already have the file checked out.)

      Using Get-PWDocumentAuditTrailRecords I was able to retrieve the info. This may be slow if your documents have a lot of audit trail records.

      $atrails = Get-PWDocumentAuditTrailRecords -FolderPath 'pw\path' -DocumentName 'TestFile.txt'
      $expRec = @($atrails | Where Action -eq 'Document Export' | Sort Action_Time -Descending)[0]
      $expRec | Select Action_Time,Action,Item_Name,Text_Param
      ($Node,$Path) = $expRec.Text_Param.Split('|')
      
      

      The line where i put @() around the statements is a trick to force the results of the commands into an array. The [0] gets the first element of the array (which because we sorted by the action time will be the last export that occurred)

      The Text_Param propert of the audit trail contains the path info. It's in the form of the node where it was exported, vertical bar, path it was exported to.

      You should verify the file is still actually exported before using this, if the file was freed or imported since the export the above will still find the info for the last time the file was exported even though it's no longer valid.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Casper Roubos
      0 Offline Casper Roubos Mon, Apr 25 2022 4:55 PM in reply to Kevin van Haaren

      Thanks for figuring out!  I can surely use it. A pity that 'CheckedOutLocalFileName' is not in use, that would be a very clean way to expose that kind of info.

      I am curious, would it be also helpful for others if the path info is accessible by a cmdlet? Is a feature request for getting this info a possible benefit for more programmers?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Casper Roubos
      0 Offline Casper Roubos Mon, Apr 25 2022 4:55 PM in reply to Kevin van Haaren

      Thanks for figuring out!  I can surely use it. A pity that 'CheckedOutLocalFileName' is not in use, that would be a very clean way to expose that kind of info.

      I am curious, would it be also helpful for others if the path info is accessible by a cmdlet? Is a feature request for getting this info a possible benefit for more programmers?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    • Kevin van Haaren
      0 Offline Kevin van Haaren Mon, Apr 25 2022 5:12 PM in reply to Casper Roubos

      For exported files I can see this, for checked out files I think the reason they don't populate it is because it depends on the user. I don't think the information is stored in the database (the audit trail doesn't get that info on checkout), i think it's stored in the user's local document organizer only.

      You can calculate it, but i suspect it might be slow, by taking the user that has it checked out and getting their working directory, then appending the documen's folder id, looking up the folder properties and then:

      $userWkDir = Join-Path -Path $WorkDir -ChildPath $Folder.Code

      $checkout = Join-Path -Path $userWkDir -ChildPath $doc.FileName

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Mon, Apr 25 2022 5:23 PM in reply to Kevin van Haaren

      I got curious how hard this would be to produce. Here's what I came up with (this is for check outs, not exports)

      $coDoc = Get-PWDocumentsBySearch # options to find checked out document
      $fcode = (Get-PWFolders -FolderID $coDoc.ProjectID -JustOne).Code
      $workDir = (Get-PWUserSettingByUser -InputUser $coDoc.DocumentOutTo -SettingName WorkDir_WhenUsingPWExplorer).UserSettingValue
      $userWkDir = Join-Path -Path $workDir -ChildPath $fcode
      $coLocation = Join-Path -Path $userWkDir -ChildPath $coDoc.FileName

      That does no error checking and assumes the $coDoc is actually a checked out document (and only one i think, not sure it works with a list of them)

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Mon, Apr 25 2022 5:27 PM in reply to Kevin van Haaren

      Document checkout info doesn't include the node the document was checked out to. I know it's available because you can turn it on as a view column. With this added in you could construct a UNC to an admin share on that computer.

      Just replace c: in the path with

      \\$node\c$\

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies