Open Sharepoint server's pdf file in

Posted on 2009-12-20
Last Modified: 2012-06-27

Want to Open a pdf file in  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..
Question by:TekiSreelakshmi
    LVL 12

    Accepted 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!
    LVL 12

    Expert Comment

    Just forgot to mention, you need to download the file first and when its done then you can stream it out from your application.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now