1

For a business application we are storing documents on Sharepoint Online (word, pdf, powerpoint, ...). The application makes use of Microsoft Graph to get the list of files and metadata. All users however have the sharepoint site 'synced' with their OneDrive Business for local storage/offline use.

The user is presented with an 'open file' button to allow him to open the file and make changes. But how can I make use of the microsoft graph api to open the local file and not the browser with the online version of the file.

Or at least get the local 'path' of the file so it can be opend using Process.Start

MythJuha
  • 11
  • 4
  • Check the [related thread](https://stackoverflow.com/questions/44416279/c-sharp-onedrive-for-business-sharepoint-get-server-path-from-locally-synced) to start with. – Dev Jul 01 '21 at 09:05

1 Answers1

0

Currently managed to do it with a similar technique also making use of the registry. Though looking through all google results I found, the registry keys and locations have changed a lot over the years. So would deffinatly prefer an 'official' method built into Microsoft.Graph or using a ms-onedrive: link, similar to ms-word: links, etc ...

public static class ListExtensions
{
    public static String GetLocalPath(this List item)
    {
        var onedriveKey = Registry.CurrentUser.OpenSubKey(@"Software\SyncEngines\Providers\OneDrive");

        foreach (var subkeyName in onedriveKey.GetSubKeyNames())
        {
            var subkey = onedriveKey.OpenSubKey(subkeyName);

            var url = subkey.GetValue("UrlNamespace").ToString().Trim('/');

            if (url == item.WebUrl)
                return (String) subkey.GetValue("MountPoint");
        }

        return null;
    }
}

public static async Task<String> GetDocumentLocalPath(DocumentSharepoint document)
    {
        var list = await GetList(document.Library);
        var path = list.GetLocalPath();

        if (path == null)
            return null;

        return $"{path}/{document.FullName}";
    }
MythJuha
  • 11
  • 4