title: C# - Find local directory of Sharepoint File
body: <p>I am trying to return the local C Drive directory of a locally sync'd Sharepoint Excel File using a C# Excel Add-in. Looking up the Excel.Application.ActiveWorkbook.FullName or .Path properties for an opened local Sharepoint file will return the Sharepoint URL (e.g. &quot;https://xxx.sharepoint.com/sites/...&quot;) and not the Local C: Drive Directory string.</p>
  <p>I have found existing solutions for OneDrive that use Environment Variables to parse out a Local Directory string (see &quot;C# Version&quot; comment in the following thread): <a href="https://social.msdn.microsoft.com/Forums/en-US/1331519b-1dd1-4aa0-8f4f-0453e1647f57/how-to-get-physical-path-instead-of-url-onedrive?forum=officegeneral" rel="nofollow noreferrer">https://social.msdn.microsoft.com/Forums/en-US/1331519b-1dd1-4aa0-8f4f-0453e1647f57/how-to-get-physical-path-instead-of-url-onedrive?forum=officegeneral</a></p>
  <p>However, I'm hoping to find a tried and true solution to cover Sharepoint local file directories as well. The problem is, the OneDrive method does not work to produce the correct local directory string because the Sharepoint URL is quite disparate from the Local Directory string.</p>
  <p>Comparison example:</p>
  <ul>
  <li><strong>Sharepoint URL returned by ActiveWorkbook.Path:</strong></li>
  </ul>
  <p><a href="https://xxx.sharepoint.com/sites/Clients/Shared" rel="nofollow noreferrer">https://xxx.sharepoint.com/sites/Clients/Shared</a> Documents/Region/Country/Client Name/Review</p>
  <ul>
  <li><strong>Actual Local File Directory:</strong></li>
  </ul>
  <p>C:\Users\MyUser\Sharepoint Parent Folder Name\Clients - Client Name\Review</p>
  <p>You can see that much of the Sharepoint URL is left out of the actual Local File Directory (namely &quot;/SharedDocuments/Region/Country&quot;). Also, &quot;Clients&quot; and &quot;Client Name&quot; are concatenated with a &quot; - &quot; separator. The local directory created after Sharepoint Local Sync is clearly some truncated version of the URL path, depending on the Sharepoint folder that was selected for local sync. This makes it difficult to programmatically recreate a Local Directory string like in the OneDrive solution.</p>
  <p>I'm hoping someone has encountered this before and could offer some guidance. It's wild to me that you can right click on a locally sync'd Sharepoint file and find a &quot;Location&quot; with the Local Directory string right there in Properties, but identifying it with C# is not straightforward. Let me know if any additional details could be provided, and many thanks.</p>