1

I have some enquires on getting all the users that currently co-editing the document, I am aware of a column in documents page called "Modified By", which I can get it by using SPList. However, it only returns the last user that modified the document. But I need to retrieve all the users that are currently in the document right now.

I was researching and found of a few potential methods, but would really appreciate if someone could offer some advice:

  1. In the info tab of word document native app, when I launch co-edit I am able to see the full list of people currently editing the document, but is there a way of extracting the list out with an api call, or SPList?

  2. In Sessions List that shows all sessions, can I create another column for modified by? So it will be easy to iterate through all the sessions and extract which users are in the same document (current sessions do not show)

3.I found some ways online suggesting to use "users = document.GetFileLevelUserCheckOutStatus()" and then "users.Value" we have to iterate users.Value so it returns all users editing the current document.

I'm not very sure on which is the better way and also I do not know which one works at the moment, would appreciate if someone could shed some light on this. Using Sharepoint 2019.

1 Answer 1

0

I don't think there is any SharePoint API at the moment where we can get a list of accounts currently editing a document. If at any point in time one is made available I would love to know myself.

That said, there is a way using Word's interop class which actually fires up a Word instance to get information about a document.

I had to do something similar recently and I've used the CoAuthoring.Authors Property to accomplish this.

The process is as follows:

  1. open Word
  2. open the specified document in edit mode - this is a must-have
  3. A query over CoAuthoring.Authors will return all the sessions, including the one that we're using to perform the query
  4. close the document (discard changes)
  5. close Word

Code

$wordApp = New-Object -ComObject Word.Application
$wordApp.Visible = $true
$document = $wordApp.Documents.Open($fileUrl)
$authors = $document.CoAuthoring.Authors
foreach($author in $authors)
{
    write-host("WORD SESSION ID: " + $author.ID + " USERNAME: " + $author.Name)
}
$document.Close(0)
$wordApp.Quit(0)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wordApp) | out-null

I'm not suggesting to use interop, in fact I would avoid it, but I thought it was an interesting find and perhaps it can help someone down the line.

Caveats:

  • Must have Word installed locally
  • Must have explicit access rights (in order to open & edit)
  • Only supports Word documents, not Excel or other types

More on interop,

https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/interop/how-to-access-office-interop-objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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