1

I have a C# desktop application which uses ADAL and the SharePoint Online CSOM to access SharePoint Online. The CSOM methods all work great, but sometimes I use a HttpWebRequest when I need to resolve a document ID URL to a file path (and I don't know which site or library the file is in). Even though I am setting the authorization header of the HttpWebRequest to the access token, the response's HTTP status is 401. Any suggestions on how to fix this?

I setup an AppRegistration in Azure as a native application with "Read and write items and lists in all site collections" permission. I didn't see any other applicable permissions that I would need to access the DocIdRedir.aspx page.

Update:
I am adding my ADAL token to a web request with the following properties:

URL: /_layouts/15/DocIdRedir.aspx?ID=F7YNH7UCH7KU-2102554853-455834
AllowAutoRedirect: False
KeepAlive: True
Method: HEAD
PreAuthenticate: True
Headers: Authorization: Bearer xxxxxxxx

The response I get back is a 401 Unauthorized with a "WWW-Authenticate" header. When I use a cookie container instead, everything works great.

So I am wondering if it is possible to use tokens with the DocIdRedir.aspx page?

  • I've tried setting AllowAutoRedirect to True and Method to GET, but I get the same result. – Steve Aug 14 '18 at 15:46
1

If the CSOM works great perhaps it would be an idea to retrieve the file info using CSOM search. Once you have the path you'll be able to spin up the proper clientcontext :-)

  • I tried that, but I was not able to get it to work. I used a QueryText set to the doc ID (e.g. "F7YNH7UCH7KU-2102554853-454904"), but the search never found any results. – Steve Jul 28 '18 at 14:40
  • That is strange, if the item is in the Search index. Does it show up in the search query tool, or like shown here richardstk.com/2014/12/12/… – Kasper Bo Larsen Jul 28 '18 at 14:56
  • No, it does not. These are test files that I recently copied to the document library. I'm wondering if the search crawler has not indexed them yet. – Steve Jul 28 '18 at 14:58
  • It should show up within 15 min, otherwise try to force a reload of the library using the reindex option under advanced settings. If that doesn't solve the index there is Michael Svensons reindex site collection script – Kasper Bo Larsen Jul 28 '18 at 15:24
  • It's been 40 minutes now and still does not show up. The doc ID URL from the file properties works when clicked, but the search still does not. If I search for the item ID ("454904"), I find the file, but I would prefer to use a search that is unique to the particular file I am looking for. – Steve Jul 28 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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