0

I'm querying the graph api using this URL:

https://graph.microsoft.com/v1.0/sites/{siteID}/drives/{driveID}/root/children

which is giving me the webURL

"https://MY DOMAIN.sharepoint.com/sites/{SITE}/{FILENAME}.url

Is there any way to get the value that the shortcut item points to, as opposed to downloading a .url file?

I think Get url address from url file answers half of my question, however, I'm unable to get the contents of the url as a File type object to be able to read through it.

I'm getting each of the quicklinks and adding them to a list via ReadAsStringAsync

public static async Task<List<QuickLinkViewModel>> GetQuickLinksAsync (dynamic quicklinksJson)
    {
        List<QuickLinkViewModel> quickLinks = new List<QuickLinkViewModel>();


        var quickLink = quicklinksJson.value;
        string title;

        HttpClient client = new HttpClient();
        byte[] reply;

        foreach (var q in quickLink)
        {
            reply = await client.GetByteArrayAsync(q.webUrl);


            title = q.name;
            title = System.IO.Path.GetFileNameWithoutExtension(title);
            quickLinks.Add(new QuickLinkViewModel
            {
                Title = title,
                webUrl = q.webUrl
            });
        }

        return quickLinks;
    }

When I run this I'm getting the error:

The best overloaded method match for 'System.Net.Http.HttpClient.GetByteArrayAsync(string)' has some invalid arguments

1 Answers1

0

.url file is not supported to be previewed in SharePoint. So the webUrl format in the query results of Microsoft Graph is different from other files. Other files can be previewed through this webUrl. The .url file will be downloaded directly through webUrl.

You can download it and open it with the edit tool to see the value that the shortcut item points to.

The content of .url file:

[InternetShortcut]
URL={the value that the shortcut item points to}

UPDATE:

If you want to get the content of the .url file in your code, you need to call another Graph endpoint: GET /drives/{drive-id}/items/{item-id}/content. See reference here. Use client.DownloadString to read the content in C#.

Here is a simple example (Please note that I didn't implement the authorization process here, just put the Authorization herder for convenience):

enter image description here

Allen Wu
  • 15,529
  • 1
  • 9
  • 20