Results 1 to 4 of 4

Thread: Downloading a PDF File from a URL

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

    Downloading a PDF File from a URL

    Good Day All

    i have a Reporting Service URL that i dynamically pass the Parameters on a Querystrng and if i take that URL and post it on a BRowser it downloads the PDF file. so i want to do this in C# , this code runs in a WCF service


    Code:
            public void GetAccountEmailStatement(string AccountNumber, string EmailAddress)
            { 
                try
                {
                    //  
                    
                    string remoteUri = "http://myserver/ReportServer/Pages/ReportViewer.aspx?%2fE-Billing%2fISU_PDF_GEN_1&rs:Command=Render&Contract_Account_Number=" + AccountNumber + "&Post_Date=26/02/15&rs:Format=PDF";
                    string fileName = HttpContext.Current.Server.MapPath("/Temp/"  + AccountNumber + ".pdf");  
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile(remoteUri, fileName); //Error hapeens on this line
     
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                finally
                {
                    this.con.Close();
                } 
            }
    The Error i get when its supposed to download the file is


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

    Please help

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: Downloading a PDF File from a URL

    sounds like you need credentials to download that file
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

    Re: Downloading a PDF File from a URL

    Thanks for the Reply, i have access to the reporting server. what should i do to make this work in terms of credentials, do i add a user for this service in Reporting Service and make a change on the Service to accommodate that user ?

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Downloading a PDF File from a URL

    odds are there is more than whats in the querystring being passed that is the problem. I'm guessing that there's a cookie or something that needs to be set as part of the request. Try using Fiddler to see what is bei ng passed between tbhe client and reporting services... you may need to mimmic more than the qs.
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width