Open SharePoint Online 365 document from other application without prompt credentials

Suresh S 96 Reputation points
2020-08-06T14:48:18.973+00:00

Hi All,

We are maintaining the document repository in SharePoint online 365. All the documents related activities are maintained here.

We have a requirement to open the SharePoint online documents URL from another application /outside of SharePoint Online without prompt the credentials. Without download, we want to open to the SharePoint Online document URL from another application. Please how can I do it?

Is there any API or someother feasibility to open the URL from anoher application without prompt.

Thanks & Regards
Suresh S

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
{count} votes

Answer accepted by question author
  1. Suresh S 96 Reputation points
    2020-08-07T15:35:51.87+00:00

    Hi Jerryzy,

    Thank you for the solution. But here your code is downloading the file as a stream which is equalent to download the document. If 100 users open the documents then it will be data lose and performance issue.

    Is it possible to open the document, without download the stream?

    Thank you
    Suresh S


4 additional answers

Sort by: Most helpful
  1. trevorseward 11,711 Reputation points
    2020-08-06T15:08:18.68+00:00

    Your user would need to log into M365. This can typically be accelerated (made automatic) by implement Azure AD Connect Seamless SSO (https://dori-uw-1.kuma-moon.com/en-us/azure/active-directory/hybrid/how-to-connect-sso) or on Windows, join the client machine to Azure AD and have the user log into Windows with AAD credentials.

    The application itself needs to integrate with Azure AD, i.e. leveraging Azure AD SSO which may require development effort. It's hard to give you advice on how to do this without knowing more about the application. If the application comes from a 3rd party (i.e. you don't have the source code to implement this), you would need to go back to the vendor to request proper integration with Azure AD.

    1 person found this answer helpful.

  2. Suresh S 96 Reputation points
    2020-08-07T07:16:56.27+00:00

    Hi All,

    I have tried the below code,

    ClientContext ctx = new ClientContext(siteCollectionUrl); SecureString secureString = new SecureString(); password.ToList().ForEach(secureString.AppendChar); ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);
    Site site = ctx.Site;
    var file = ctx.Web.GetFileByServerRelativeUrl("/sites/Test/TestSPOnline/Shared Documents//1001/OPL01-00000762.pdf");
    ctx.Load(file);
    ctx.ExecuteQuery();

    The document is loaded in the ClientContext object. I want to open the document in the browser without download.

    0 comments No comments

  3. ZhengyuGuo 10,591 Reputation points Moderator
    2020-08-07T09:30:30.633+00:00

    Hi @Suresh S ,

    You can get file and open in browser as the code snippet in attachment:

    16443-code.png

    Reference:

    How to Open PDF Files in Web Brower Using ASP.NET

    0 comments No comments

  4. Suresh S 96 Reputation points
    2020-08-10T04:36:57.033+00:00

    HI Jerryzy,

    Thank you for the update. Can you provide me your thoughts that I want to open the SharePoint documents in browser from other/independent applications without credentials prompt? I have only documents URL in independent application/ Programmatically I want to authenticate the URL and open the document without download or stream. Download and streams will take time for large files when multiple users access the same url.

    Is there any in Built Web APIs provided by Microsoft to access the documents URL programmatically without download?

    Please advise me. Is the below code appropriate for my need? I am directly getting the stream from HttpResponse without looping.

    HttpWebRequest request;
    request = (HttpWebRequest)WebRequest.Create(strFileUrl); // SharePoint document URL
    request.Timeout = 600000000;
    request.CookieContainer = new CookieContainer();
    request.CookieContainer.Add(cookie); // Authentication using cookie
    request.AllowWriteStreamBuffering = false;
    byte[] read = null;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream str = response.GetResponseStream();
    MemoryStream ms = new MemoryStream();
    str .CopyTo(ms);
    read = ms.ToArray();

    Please provide your thoughts.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.