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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,704 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,576 questions
{count} votes

Accepted answer
  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. Trevor Seward 11,681 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://learn.microsoft.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. Jerryzy 10,566 Reputation points
    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:

    16358-code.txt

    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.