Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Open Sharepoint server's pdf file in asp.net...


Want to Open a pdf file in asp.net  which is in the sharepoint server..
I 've used the code below...

            System.Net.WebClient client = new System.Net.WebClient();

            string path = "http://hawaii:9999/Functions/HumanResource/HR/Employee%20Handbook/GE%20Emp%20Handbook.pdf";

            Byte[] buffer = client.DownloadData(path);

            if (buffer != null)
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-length", buffer.Length.ToString());
Then its giving exception like

The remote server returned an error: (401) Unauthorized.

what to do to solve this problem..
  • 2
1 Solution
You need to pass credentials for accessing the file. For example, use networkcredential and pass username and password of a sharepoint user of that site.
For checking purpose, try opening that url in internet explorer with the sharepoint user name and password, if it opens, the credentials are correct and modify your current code to use the credentials.

Otherway around is to use sharepoint webservice to download the document, but its the hard way and let me know if the above scenario does not work, we'll look into this one.
Happy Coding!
Just forgot to mention, you need to download the file first and when its done then you can stream it out from your asp.net application.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now