What does the "sourcedoc" part of a SharePoint filepath represent?

Copper Contributor

Hi all,

 

I've been working on opening sharepoint files with VBA (reference PowerPoint decks via a ribbon button).

 

I'm using "Application.ActivePresentation.FollowHyperlink SharePointPath" which is working fine.

 

The constant SharePointPath is the direct SharePoint link for the files I want, which takes this form:

https://tenant.sharepoint.com/:p:/r/sites/sitecollection/_layouts/15/Doc.aspx?sourcedoc=%7BB60C7EC5-A285-4BC7-9B0B-B98A148A26D7%7D&file=filename.pptx

 

I've been testing different combinations of replacing the file in place, changing the filename, etc. to see how this can be broken and have noticed a strange behaviour. When I:

- Uploaded a different file to the same folder

- Deleted the original file

- Renamed the new file to the filename of the old file

I got a different "sourcedoc" (the bit in blue), however, the original link still worked.

 

To play out the example:

- I uploaded a file, which had this path

https://tenant.sharepoint.com/:p:/r/sites/sitecollection/_layouts/15/Doc.aspx?sourcedoc=xxxxxx&file=originalfilename.pptx (this path was put in the constant "SharePointPath" in VBA)

 

- I uploaded a new file, which had this path

https://tenant.sharepoint.com/:p:/r/sites/sitecollection/_layouts/15/Doc.aspx?sourcedoc=yyyyyy&file=newfilename.pptx

 

- I renamed the new file to the filename of the original file, which then had this path

https://tenant.sharepoint.com/:p:/r/sites/sitecollection/_layouts/15/Doc.aspx?sourcedoc=yyyyyy&file=originalfilename.pptx

 

- Then tried "Application.ActivePresentation.FollowHyperlink SharePointPath" WITHOUT updating SharePointPath (so the path was the xxxxxx path) and it still successfully opened the new file.

 

So my question is, what is that "sourcedoc" reference? What does it represent and why didn't it matter that I changed it? I have seen it is a "document_GUID" but not clear on how it works why it didn't matter that it changed

2 Replies

@Sleepy319  I to am having the same questions. My biggest question is how can I find the sourcedoc to use it? I am trying to open office documents in a modal with 0 success. I can open pdf's all day in a modal with no issues, but not office.  If anyone knows how to extract the sourcedoc using JavaScript, I'd be more than appreciative to find the answer.

@Sleepy319 to achieve the behavior you're looking for, you need to refine the link provided to ensure that documents open in the SharePoint Online document viewer. This involves formatting the URLs in a way that directs users to the Office Online viewer integrated into SharePoint. 

Construct the URL to follow this pattern:

https://<SharePoint-Site-URL>/<Document-Library>/Forms/AllItems.aspx?id=<Document-Library>/<File-Name>&parent=/<Document-Library>