System.Net.WebClient.DownloadFile doesn't work with http attachments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • A.M-SG

    System.Net.WebClient.DownloadFile doesn't work with http attachments

    Hi,

    I have an aspx page at the web server that provides PDF documents for smart
    client applications.

    Here is the code in aspx page that defines content type:

    Response.Conten tType = "applicatio n/octet-stream";
    Response.Append Header("Content-Disposition", "attachment;fil ename=" +
    fileID.ToString () + ".pdf");

    I tested the aspx page by using browser and it works just fine.

    Now I need to receive that file by using the
    System.Net.WebC lient.DownloadF ile. The problem is that DownloadFile method
    returns the following exception:

    "Unable to read data from the transport connection: The connection was
    closed."

    I tested the DownloadFile method to open a direct pdf file like the
    following statement:

    (new
    System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf");

    It works just fine.

    How can I use System.Net.WebC lient. DownloadFile to download http
    attachments?

    Any help would be apprecited,
    Alan


  • Steven Cheng[MSFT]

    #2
    RE: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

    Hi Alan,

    Welcome to MSDN newsgroup.
    Regarding on the file downloading through WebClient class problem you
    mentioned, seems a bit strange from a general view. It is possible a
    machine specific issue. here is a test page's code which could be correctly
    used (let client user webbrowser or webclient class to download the file)
    on my side:

    =============== ===
    private void Page_Load(objec t sender, System.EventArg s e)
    {
    Response.ClearH eaders();
    Response.ClearC ontent();
    Response.Conten tType = "applicatio n/octet-stream";

    Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");

    Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));

    Response.End();
    }
    =============== ===

    You can try the above code in your page to see whether it works. Also, you
    can run the webclient from multiple client to see whether it is client
    specific.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)




    --------------------
    | From: "A.M-SG" <alanalan@newsg roup.nospam>
    | Subject: System.Net.WebC lient.DownloadF ile doesn't work with http
    attachments
    | Date: Mon, 31 Oct 2005 18:45:48 -0500
    | Lines: 35
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
    | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
    | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
    | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca 65.92.97.129
    | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
    | Xref: TK2MSFTNGXA01.p hx.gbl
    microsoft.publi c.dotnet.langua ges.csharp:1330 60
    | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
    |
    | Hi,
    |
    | I have an aspx page at the web server that provides PDF documents for
    smart
    | client applications.
    |
    | Here is the code in aspx page that defines content type:
    |
    | Response.Conten tType = "applicatio n/octet-stream";
    | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
    | fileID.ToString () + ".pdf");
    |
    | I tested the aspx page by using browser and it works just fine.
    |
    | Now I need to receive that file by using the
    | System.Net.WebC lient.DownloadF ile. The problem is that DownloadFile
    method
    | returns the following exception:
    |
    | "Unable to read data from the transport connection: The connection was
    | closed."
    |
    | I tested the DownloadFile method to open a direct pdf file like the
    | following statement:
    |
    | (new
    |
    System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
    ");
    |
    | It works just fine.
    |
    | How can I use System.Net.WebC lient. DownloadFile to download http
    | attachments?
    |
    | Any help would be apprecited,
    | Alan
    |
    |
    |

    Comment

    • A.M-SG

      #3
      Re: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

      Hi Steven,

      Firstly thank you for your reply.

      The code that you provided is not my question.

      My question is: "How to receive that pdf file at the client side?"

      The server side is done and it is similar to what you mentioned in your
      reply.

      I tried to receive the pdf file (test.pdf in your sample) by using
      System.Net.WebC lient.DownloadF ile, but it throws exception.

      Regards,
      Alan



      "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
      news:CXg1MTu3FH A.3220@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
      > Hi Alan,
      >
      > Welcome to MSDN newsgroup.
      > Regarding on the file downloading through WebClient class problem you
      > mentioned, seems a bit strange from a general view. It is possible a
      > machine specific issue. here is a test page's code which could be
      > correctly
      > used (let client user webbrowser or webclient class to download the file)
      > on my side:
      >
      > =============== ===
      > private void Page_Load(objec t sender, System.EventArg s e)
      > {
      > Response.ClearH eaders();
      > Response.ClearC ontent();
      > Response.Conten tType = "applicatio n/octet-stream";
      >
      > Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");
      >
      > Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));
      >
      > Response.End();
      > }
      > =============== ===
      >
      > You can try the above code in your page to see whether it works. Also, you
      > can run the webclient from multiple client to see whether it is client
      > specific.
      >
      > Thanks,
      >
      > Steven Cheng
      > Microsoft Online Support
      >
      > Get Secure! www.microsoft.com/security
      > (This posting is provided "AS IS", with no warranties, and confers no
      > rights.)
      >
      >
      >
      >
      > --------------------
      > | From: "A.M-SG" <alanalan@newsg roup.nospam>
      > | Subject: System.Net.WebC lient.DownloadF ile doesn't work with http
      > attachments
      > | Date: Mon, 31 Oct 2005 18:45:48 -0500
      > | Lines: 35
      > | X-Priority: 3
      > | X-MSMail-Priority: Normal
      > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
      > | X-RFC2646: Format=Flowed; Original
      > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
      > | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
      > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
      > | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca 65.92.97.129
      > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
      > | Xref: TK2MSFTNGXA01.p hx.gbl
      > microsoft.publi c.dotnet.langua ges.csharp:1330 60
      > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
      > |
      > | Hi,
      > |
      > | I have an aspx page at the web server that provides PDF documents for
      > smart
      > | client applications.
      > |
      > | Here is the code in aspx page that defines content type:
      > |
      > | Response.Conten tType = "applicatio n/octet-stream";
      > | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
      > | fileID.ToString () + ".pdf");
      > |
      > | I tested the aspx page by using browser and it works just fine.
      > |
      > | Now I need to receive that file by using the
      > | System.Net.WebC lient.DownloadF ile. The problem is that DownloadFile
      > method
      > | returns the following exception:
      > |
      > | "Unable to read data from the transport connection: The connection was
      > | closed."
      > |
      > | I tested the DownloadFile method to open a direct pdf file like the
      > | following statement:
      > |
      > | (new
      > |
      > System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
      > ");
      > |
      > | It works just fine.
      > |
      > | How can I use System.Net.WebC lient. DownloadFile to download http
      > | attachments?
      > |
      > | Any help would be apprecited,
      > | Alan
      > |
      > |
      > |
      >[/color]


      Comment

      • Steven Cheng[MSFT]

        #4
        Re: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

        Hi Alan,

        Yes, I know the serverside code won't have big difference , nor does the
        client code. That's why I think this should be a environment specific
        issue. Here is the client code I've used to test , (both use WebClient and
        HttpWebRequest ....) , the code work correctly on my test environment.

        =============== ==========
        static void Main(string[] args)
        {


        DownloadByWebCl ient();


        DownloadByHttpW ebRequest();
        }

        static void DownloadByWebCl ient()
        {
        string url =
        "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
        string clientfile = @"d:\temp\test_ webclient.pdf";

        WebClient wc = new WebClient();

        wc.DownloadFile (url,clientfile );

        }

        static void DownloadByHttpW ebRequest()
        {
        string url =
        "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
        string clientfile = @"d:\temp\test_ webrequest.pdf" ;

        HttpWebRequest req = WebRequest.Crea te(url) as HttpWebRequest;

        req.Method = "GET";
        req.KeepAlive = true;

        HttpWebResponse rep = req.GetResponse () as HttpWebResponse ;

        Stream stream = rep.GetResponse Stream();

        FileStream fs = new FileStream(clie ntfile, FileMode.Create ,
        FileAccess.Writ e);

        byte[] buf = new byte[1024];

        int i = 0;

        while( (i=stream.Read( buf,0,buf.Lengt h))> 0)
        {
        fs.Write(buf,0, i);
        }

        fs.Close();

        stream.Close();

        rep.Close();

        }
        =============== =============

        In addition, you can also try comment the below line in your serverside
        code to see whether it helps:

        Response.Append Header("Content-Disposition", "attachment;fil ename=" +
        fileID.ToString () + ".pdf");

        Thanks,

        Steven Cheng
        Microsoft Online Support

        Get Secure! www.microsoft.com/security
        (This posting is provided "AS IS", with no warranties, and confers no
        rights.)

        --------------------
        | From: "A.M-SG" <alanalan@newsg roup.nospam>
        | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
        <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
        | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
        attachments
        | Date: Tue, 1 Nov 2005 08:15:42 -0500
        | Lines: 124
        | X-Priority: 3
        | X-MSMail-Priority: Normal
        | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
        | X-RFC2646: Format=Flowed; Original
        | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
        | Message-ID: <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
        | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        | NNTP-Posting-Host: toronto-hse-ppp4253404.symp atico.ca 70.52.252.114
        | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
        | Xref: TK2MSFTNGXA01.p hx.gbl
        microsoft.publi c.dotnet.langua ges.csharp:1331 23
        | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        |
        | Hi Steven,
        |
        | Firstly thank you for your reply.
        |
        | The code that you provided is not my question.
        |
        | My question is: "How to receive that pdf file at the client side?"
        |
        | The server side is done and it is similar to what you mentioned in your
        | reply.
        |
        | I tried to receive the pdf file (test.pdf in your sample) by using
        | System.Net.WebC lient.DownloadF ile, but it throws exception.
        |
        | Regards,
        | Alan
        |
        |
        |
        | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
        | news:CXg1MTu3FH A.3220@TK2MSFTN GXA01.phx.gbl.. .
        | > Hi Alan,
        | >
        | > Welcome to MSDN newsgroup.
        | > Regarding on the file downloading through WebClient class problem you
        | > mentioned, seems a bit strange from a general view. It is possible a
        | > machine specific issue. here is a test page's code which could be
        | > correctly
        | > used (let client user webbrowser or webclient class to download the
        file)
        | > on my side:
        | >
        | > =============== ===
        | > private void Page_Load(objec t sender, System.EventArg s e)
        | > {
        | > Response.ClearH eaders();
        | > Response.ClearC ontent();
        | > Response.Conten tType = "applicatio n/octet-stream";
        | >
        | >
        Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");
        | >
        | > Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));
        | >
        | > Response.End();
        | > }
        | > =============== ===
        | >
        | > You can try the above code in your page to see whether it works. Also,
        you
        | > can run the webclient from multiple client to see whether it is client
        | > specific.
        | >
        | > Thanks,
        | >
        | > Steven Cheng
        | > Microsoft Online Support
        | >
        | > Get Secure! www.microsoft.com/security
        | > (This posting is provided "AS IS", with no warranties, and confers no
        | > rights.)
        | >
        | >
        | >
        | >
        | > --------------------
        | > | From: "A.M-SG" <alanalan@newsg roup.nospam>
        | > | Subject: System.Net.WebC lient.DownloadF ile doesn't work with http
        | > attachments
        | > | Date: Mon, 31 Oct 2005 18:45:48 -0500
        | > | Lines: 35
        | > | X-Priority: 3
        | > | X-MSMail-Priority: Normal
        | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
        | > | X-RFC2646: Format=Flowed; Original
        | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
        | > | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
        | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        | > | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca 65.92.97.129
        | > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
        | > | Xref: TK2MSFTNGXA01.p hx.gbl
        | > microsoft.publi c.dotnet.langua ges.csharp:1330 60
        | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        | > |
        | > | Hi,
        | > |
        | > | I have an aspx page at the web server that provides PDF documents for
        | > smart
        | > | client applications.
        | > |
        | > | Here is the code in aspx page that defines content type:
        | > |
        | > | Response.Conten tType = "applicatio n/octet-stream";
        | > | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
        | > | fileID.ToString () + ".pdf");
        | > |
        | > | I tested the aspx page by using browser and it works just fine.
        | > |
        | > | Now I need to receive that file by using the
        | > | System.Net.WebC lient.DownloadF ile. The problem is that DownloadFile
        | > method
        | > | returns the following exception:
        | > |
        | > | "Unable to read data from the transport connection: The connection was
        | > | closed."
        | > |
        | > | I tested the DownloadFile method to open a direct pdf file like the
        | > | following statement:
        | > |
        | > | (new
        | > |
        | >
        System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
        | > ");
        | > |
        | > | It works just fine.
        | > |
        | > | How can I use System.Net.WebC lient. DownloadFile to download http
        | > | attachments?
        | > |
        | > | Any help would be apprecited,
        | > | Alan
        | > |
        | > |
        | > |
        | >
        |
        |
        |

        Comment

        • Steven Cheng[MSFT]

          #5
          Re: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

          Hi Alan,

          How are you doing on this issue, have you got any further progress? If
          there're anything else we can help, please feel free to post here. Thanks,

          Steven Cheng
          Microsoft Online Support

          Get Secure! www.microsoft.com/security
          (This posting is provided "AS IS", with no warranties, and confers no
          rights.)
          --------------------
          | X-Tomcat-ID: 66213528
          | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
          <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
          <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
          | MIME-Version: 1.0
          | Content-Type: text/plain
          | Content-Transfer-Encoding: 7bit
          | From: stcheng@online. microsoft.com (Steven Cheng[MSFT])
          | Organization: Microsoft
          | Date: Wed, 02 Nov 2005 03:37:50 GMT
          | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
          attachments
          | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | Message-ID: <8hGwY713FHA.11 44@TK2MSFTNGXA0 1.phx.gbl>
          | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | Lines: 167
          | Path: TK2MSFTNGXA01.p hx.gbl
          | Xref: TK2MSFTNGXA01.p hx.gbl
          microsoft.publi c.dotnet.langua ges.csharp:1333 08
          | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
          |
          | Hi Alan,
          |
          | Yes, I know the serverside code won't have big difference , nor does the
          | client code. That's why I think this should be a environment specific
          | issue. Here is the client code I've used to test , (both use WebClient
          and
          | HttpWebRequest ....) , the code work correctly on my test environment.
          |
          | =============== ==========
          | static void Main(string[] args)
          | {
          |
          |
          | DownloadByWebCl ient();
          |
          |
          | DownloadByHttpW ebRequest();
          | }
          |
          | static void DownloadByWebCl ient()
          | {
          | string url =
          | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
          | string clientfile = @"d:\temp\test_ webclient.pdf";
          |
          | WebClient wc = new WebClient();
          |
          | wc.DownloadFile (url,clientfile );
          |
          | }
          |
          | static void DownloadByHttpW ebRequest()
          | {
          | string url =
          | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
          | string clientfile = @"d:\temp\test_ webrequest.pdf" ;
          |
          | HttpWebRequest req = WebRequest.Crea te(url) as HttpWebRequest;
          |
          | req.Method = "GET";
          | req.KeepAlive = true;
          |
          | HttpWebResponse rep = req.GetResponse () as HttpWebResponse ;
          |
          | Stream stream = rep.GetResponse Stream();
          |
          | FileStream fs = new FileStream(clie ntfile, FileMode.Create ,
          | FileAccess.Writ e);
          |
          | byte[] buf = new byte[1024];
          |
          | int i = 0;
          |
          | while( (i=stream.Read( buf,0,buf.Lengt h))> 0)
          | {
          | fs.Write(buf,0, i);
          | }
          |
          | fs.Close();
          |
          | stream.Close();
          |
          | rep.Close();
          |
          | }
          | =============== =============
          |
          | In addition, you can also try comment the below line in your serverside
          | code to see whether it helps:
          |
          | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
          | fileID.ToString () + ".pdf");
          |
          | Thanks,
          |
          | Steven Cheng
          | Microsoft Online Support
          |
          | Get Secure! www.microsoft.com/security
          | (This posting is provided "AS IS", with no warranties, and confers no
          | rights.)
          |
          | --------------------
          | | From: "A.M-SG" <alanalan@newsg roup.nospam>
          | | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
          | <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
          | | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
          | attachments
          | | Date: Tue, 1 Nov 2005 08:15:42 -0500
          | | Lines: 124
          | | X-Priority: 3
          | | X-MSMail-Priority: Normal
          | | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
          | | X-RFC2646: Format=Flowed; Original
          | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
          | | Message-ID: <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
          | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | | NNTP-Posting-Host: toronto-hse-ppp4253404.symp atico.ca 70.52.252.114
          | | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
          | | Xref: TK2MSFTNGXA01.p hx.gbl
          | microsoft.publi c.dotnet.langua ges.csharp:1331 23
          | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | |
          | | Hi Steven,
          | |
          | | Firstly thank you for your reply.
          | |
          | | The code that you provided is not my question.
          | |
          | | My question is: "How to receive that pdf file at the client side?"
          | |
          | | The server side is done and it is similar to what you mentioned in your
          | | reply.
          | |
          | | I tried to receive the pdf file (test.pdf in your sample) by using
          | | System.Net.WebC lient.DownloadF ile, but it throws exception.
          | |
          | | Regards,
          | | Alan
          | |
          | |
          | |
          | | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
          | | news:CXg1MTu3FH A.3220@TK2MSFTN GXA01.phx.gbl.. .
          | | > Hi Alan,
          | | >
          | | > Welcome to MSDN newsgroup.
          | | > Regarding on the file downloading through WebClient class problem you
          | | > mentioned, seems a bit strange from a general view. It is possible a
          | | > machine specific issue. here is a test page's code which could be
          | | > correctly
          | | > used (let client user webbrowser or webclient class to download the
          | file)
          | | > on my side:
          | | >
          | | > =============== ===
          | | > private void Page_Load(objec t sender, System.EventArg s e)
          | | > {
          | | > Response.ClearH eaders();
          | | > Response.ClearC ontent();
          | | > Response.Conten tType = "applicatio n/octet-stream";
          | | >
          | | >
          |
          Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");
          | | >
          | | > Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));
          | | >
          | | > Response.End();
          | | > }
          | | > =============== ===
          | | >
          | | > You can try the above code in your page to see whether it works.
          Also,
          | you
          | | > can run the webclient from multiple client to see whether it is client
          | | > specific.
          | | >
          | | > Thanks,
          | | >
          | | > Steven Cheng
          | | > Microsoft Online Support
          | | >
          | | > Get Secure! www.microsoft.com/security
          | | > (This posting is provided "AS IS", with no warranties, and confers no
          | | > rights.)
          | | >
          | | >
          | | >
          | | >
          | | > --------------------
          | | > | From: "A.M-SG" <alanalan@newsg roup.nospam>
          | | > | Subject: System.Net.WebC lient.DownloadF ile doesn't work with http
          | | > attachments
          | | > | Date: Mon, 31 Oct 2005 18:45:48 -0500
          | | > | Lines: 35
          | | > | X-Priority: 3
          | | > | X-MSMail-Priority: Normal
          | | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
          | | > | X-RFC2646: Format=Flowed; Original
          | | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
          | | > | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
          | | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | | > | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca 65.92.97.129
          | | > | Path:
          TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
          | | > | Xref: TK2MSFTNGXA01.p hx.gbl
          | | > microsoft.publi c.dotnet.langua ges.csharp:1330 60
          | | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | | > |
          | | > | Hi,
          | | > |
          | | > | I have an aspx page at the web server that provides PDF documents
          for
          | | > smart
          | | > | client applications.
          | | > |
          | | > | Here is the code in aspx page that defines content type:
          | | > |
          | | > | Response.Conten tType = "applicatio n/octet-stream";
          | | > | Response.Append Header("Content-Disposition", "attachment;fil ename="
          +
          | | > | fileID.ToString () + ".pdf");
          | | > |
          | | > | I tested the aspx page by using browser and it works just fine.
          | | > |
          | | > | Now I need to receive that file by using the
          | | > | System.Net.WebC lient.DownloadF ile. The problem is that DownloadFile
          | | > method
          | | > | returns the following exception:
          | | > |
          | | > | "Unable to read data from the transport connection: The connection
          was
          | | > | closed."
          | | > |
          | | > | I tested the DownloadFile method to open a direct pdf file like the
          | | > | following statement:
          | | > |
          | | > | (new
          | | > |
          | | >
          |
          System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
          | | > ");
          | | > |
          | | > | It works just fine.
          | | > |
          | | > | How can I use System.Net.WebC lient. DownloadFile to download http
          | | > | attachments?
          | | > |
          | | > | Any help would be apprecited,
          | | > | Alan
          | | > |
          | | > |
          | | > |
          | | >
          | |
          | |
          | |
          |
          |

          Comment

          • A.M-SG

            #6
            Re: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

            Hi Steven.

            Yes, I got it working. Thank you for your help.

            Ali



            "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
            news:cZPb$xh4FH A.2904@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
            > Hi Alan,
            >
            > How are you doing on this issue, have you got any further progress? If
            > there're anything else we can help, please feel free to post here. Thanks,
            >
            > Steven Cheng
            > Microsoft Online Support
            >
            > Get Secure! www.microsoft.com/security
            > (This posting is provided "AS IS", with no warranties, and confers no
            > rights.)
            > --------------------
            > | X-Tomcat-ID: 66213528
            > | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
            > <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
            > <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
            > | MIME-Version: 1.0
            > | Content-Type: text/plain
            > | Content-Transfer-Encoding: 7bit
            > | From: stcheng@online. microsoft.com (Steven Cheng[MSFT])
            > | Organization: Microsoft
            > | Date: Wed, 02 Nov 2005 03:37:50 GMT
            > | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
            > attachments
            > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            > | Message-ID: <8hGwY713FHA.11 44@TK2MSFTNGXA0 1.phx.gbl>
            > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            > | Lines: 167
            > | Path: TK2MSFTNGXA01.p hx.gbl
            > | Xref: TK2MSFTNGXA01.p hx.gbl
            > microsoft.publi c.dotnet.langua ges.csharp:1333 08
            > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
            > |
            > | Hi Alan,
            > |
            > | Yes, I know the serverside code won't have big difference , nor does the
            > | client code. That's why I think this should be a environment specific
            > | issue. Here is the client code I've used to test , (both use WebClient
            > and
            > | HttpWebRequest ....) , the code work correctly on my test environment.
            > |
            > | =============== ==========
            > | static void Main(string[] args)
            > | {
            > |
            > |
            > | DownloadByWebCl ient();
            > |
            > |
            > | DownloadByHttpW ebRequest();
            > | }
            > |
            > | static void DownloadByWebCl ient()
            > | {
            > | string url =
            > | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
            > | string clientfile = @"d:\temp\test_ webclient.pdf";
            > |
            > | WebClient wc = new WebClient();
            > |
            > | wc.DownloadFile (url,clientfile );
            > |
            > | }
            > |
            > | static void DownloadByHttpW ebRequest()
            > | {
            > | string url =
            > | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
            > | string clientfile = @"d:\temp\test_ webrequest.pdf" ;
            > |
            > | HttpWebRequest req = WebRequest.Crea te(url) as HttpWebRequest;
            > |
            > | req.Method = "GET";
            > | req.KeepAlive = true;
            > |
            > | HttpWebResponse rep = req.GetResponse () as HttpWebResponse ;
            > |
            > | Stream stream = rep.GetResponse Stream();
            > |
            > | FileStream fs = new FileStream(clie ntfile, FileMode.Create ,
            > | FileAccess.Writ e);
            > |
            > | byte[] buf = new byte[1024];
            > |
            > | int i = 0;
            > |
            > | while( (i=stream.Read( buf,0,buf.Lengt h))> 0)
            > | {
            > | fs.Write(buf,0, i);
            > | }
            > |
            > | fs.Close();
            > |
            > | stream.Close();
            > |
            > | rep.Close();
            > |
            > | }
            > | =============== =============
            > |
            > | In addition, you can also try comment the below line in your serverside
            > | code to see whether it helps:
            > |
            > | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
            > | fileID.ToString () + ".pdf");
            > |
            > | Thanks,
            > |
            > | Steven Cheng
            > | Microsoft Online Support
            > |
            > | Get Secure! www.microsoft.com/security
            > | (This posting is provided "AS IS", with no warranties, and confers no
            > | rights.)
            > |
            > | --------------------
            > | | From: "A.M-SG" <alanalan@newsg roup.nospam>
            > | | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
            > | <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
            > | | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
            > | attachments
            > | | Date: Tue, 1 Nov 2005 08:15:42 -0500
            > | | Lines: 124
            > | | X-Priority: 3
            > | | X-MSMail-Priority: Normal
            > | | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
            > | | X-RFC2646: Format=Flowed; Original
            > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
            > | | Message-ID: <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
            > | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            > | | NNTP-Posting-Host: toronto-hse-ppp4253404.symp atico.ca 70.52.252.114
            > | | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
            > | | Xref: TK2MSFTNGXA01.p hx.gbl
            > | microsoft.publi c.dotnet.langua ges.csharp:1331 23
            > | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            > | |
            > | | Hi Steven,
            > | |
            > | | Firstly thank you for your reply.
            > | |
            > | | The code that you provided is not my question.
            > | |
            > | | My question is: "How to receive that pdf file at the client side?"
            > | |
            > | | The server side is done and it is similar to what you mentioned in
            > your
            > | | reply.
            > | |
            > | | I tried to receive the pdf file (test.pdf in your sample) by using
            > | | System.Net.WebC lient.DownloadF ile, but it throws exception.
            > | |
            > | | Regards,
            > | | Alan
            > | |
            > | |
            > | |
            > | | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
            > | | news:CXg1MTu3FH A.3220@TK2MSFTN GXA01.phx.gbl.. .
            > | | > Hi Alan,
            > | | >
            > | | > Welcome to MSDN newsgroup.
            > | | > Regarding on the file downloading through WebClient class problem
            > you
            > | | > mentioned, seems a bit strange from a general view. It is possible a
            > | | > machine specific issue. here is a test page's code which could be
            > | | > correctly
            > | | > used (let client user webbrowser or webclient class to download the
            > | file)
            > | | > on my side:
            > | | >
            > | | > =============== ===
            > | | > private void Page_Load(objec t sender, System.EventArg s e)
            > | | > {
            > | | > Response.ClearH eaders();
            > | | > Response.ClearC ontent();
            > | | > Response.Conten tType = "applicatio n/octet-stream";
            > | | >
            > | | >
            > |
            > Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");
            > | | >
            > | | > Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));
            > | | >
            > | | > Response.End();
            > | | > }
            > | | > =============== ===
            > | | >
            > | | > You can try the above code in your page to see whether it works.
            > Also,
            > | you
            > | | > can run the webclient from multiple client to see whether it is
            > client
            > | | > specific.
            > | | >
            > | | > Thanks,
            > | | >
            > | | > Steven Cheng
            > | | > Microsoft Online Support
            > | | >
            > | | > Get Secure! www.microsoft.com/security
            > | | > (This posting is provided "AS IS", with no warranties, and confers
            > no
            > | | > rights.)
            > | | >
            > | | >
            > | | >
            > | | >
            > | | > --------------------
            > | | > | From: "A.M-SG" <alanalan@newsg roup.nospam>
            > | | > | Subject: System.Net.WebC lient.DownloadF ile doesn't work with http
            > | | > attachments
            > | | > | Date: Mon, 31 Oct 2005 18:45:48 -0500
            > | | > | Lines: 35
            > | | > | X-Priority: 3
            > | | > | X-MSMail-Priority: Normal
            > | | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
            > | | > | X-RFC2646: Format=Flowed; Original
            > | | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
            > | | > | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
            > | | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            > | | > | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca
            > 65.92.97.129
            > | | > | Path:
            > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
            > | | > | Xref: TK2MSFTNGXA01.p hx.gbl
            > | | > microsoft.publi c.dotnet.langua ges.csharp:1330 60
            > | | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            > | | > |
            > | | > | Hi,
            > | | > |
            > | | > | I have an aspx page at the web server that provides PDF documents
            > for
            > | | > smart
            > | | > | client applications.
            > | | > |
            > | | > | Here is the code in aspx page that defines content type:
            > | | > |
            > | | > | Response.Conten tType = "applicatio n/octet-stream";
            > | | > | Response.Append Header("Content-Disposition",
            > "attachment;fil ename="
            > +
            > | | > | fileID.ToString () + ".pdf");
            > | | > |
            > | | > | I tested the aspx page by using browser and it works just fine.
            > | | > |
            > | | > | Now I need to receive that file by using the
            > | | > | System.Net.WebC lient.DownloadF ile. The problem is that
            > DownloadFile
            > | | > method
            > | | > | returns the following exception:
            > | | > |
            > | | > | "Unable to read data from the transport connection: The connection
            > was
            > | | > | closed."
            > | | > |
            > | | > | I tested the DownloadFile method to open a direct pdf file like
            > the
            > | | > | following statement:
            > | | > |
            > | | > | (new
            > | | > |
            > | | >
            > |
            > System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
            > | | > ");
            > | | > |
            > | | > | It works just fine.
            > | | > |
            > | | > | How can I use System.Net.WebC lient. DownloadFile to download http
            > | | > | attachments?
            > | | > |
            > | | > | Any help would be apprecited,
            > | | > | Alan
            > | | > |
            > | | > |
            > | | > |
            > | | >
            > | |
            > | |
            > | |
            > |
            > |
            >[/color]


            Comment

            • Steven Cheng[MSFT]

              #7
              Re: System.Net.WebC lient.DownloadF ile doesn't work with http attachments

              Thanks for your followup.

              Glad that you've got it working.
              Have a good day!

              Steven Cheng
              Microsoft Online Support

              Get Secure! www.microsoft.com/security
              (This posting is provided "AS IS", with no warranties, and confers no
              rights.)
              --------------------
              | From: "A.M-SG" <alanalan@newsg roup.nospam>
              | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
              <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
              <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
              <8hGwY713FHA.11 44@TK2MSFTNGXA0 1.phx.gbl>
              <cZPb$xh4FHA.29 04@TK2MSFTNGXA0 1.phx.gbl>
              | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
              attachments
              | Date: Mon, 7 Nov 2005 09:54:24 -0500
              | Lines: 295
              | X-Priority: 3
              | X-MSMail-Priority: Normal
              | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
              | X-RFC2646: Format=Flowed; Original
              | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
              | Message-ID: <#WZ1ks64FHA.31 92@TK2MSFTNGP12 .phx.gbl>
              | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | NNTP-Posting-Host: Toronto-HSE-ppp3736481.symp atico.ca 67.68.49.178
              | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
              | Xref: TK2MSFTNGXA01.p hx.gbl
              microsoft.publi c.dotnet.langua ges.csharp:1344 83
              | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              |
              | Hi Steven.
              |
              | Yes, I got it working. Thank you for your help.
              |
              | Ali
              |
              |
              |
              | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
              | news:cZPb$xh4FH A.2904@TK2MSFTN GXA01.phx.gbl.. .
              | > Hi Alan,
              | >
              | > How are you doing on this issue, have you got any further progress? If
              | > there're anything else we can help, please feel free to post here.
              Thanks,
              | >
              | > Steven Cheng
              | > Microsoft Online Support
              | >
              | > Get Secure! www.microsoft.com/security
              | > (This posting is provided "AS IS", with no warranties, and confers no
              | > rights.)
              | > --------------------
              | > | X-Tomcat-ID: 66213528
              | > | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
              | > <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
              | > <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
              | > | MIME-Version: 1.0
              | > | Content-Type: text/plain
              | > | Content-Transfer-Encoding: 7bit
              | > | From: stcheng@online. microsoft.com (Steven Cheng[MSFT])
              | > | Organization: Microsoft
              | > | Date: Wed, 02 Nov 2005 03:37:50 GMT
              | > | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with http
              | > attachments
              | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | > | Message-ID: <8hGwY713FHA.11 44@TK2MSFTNGXA0 1.phx.gbl>
              | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | > | Lines: 167
              | > | Path: TK2MSFTNGXA01.p hx.gbl
              | > | Xref: TK2MSFTNGXA01.p hx.gbl
              | > microsoft.publi c.dotnet.langua ges.csharp:1333 08
              | > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
              | > |
              | > | Hi Alan,
              | > |
              | > | Yes, I know the serverside code won't have big difference , nor does
              the
              | > | client code. That's why I think this should be a environment specific
              | > | issue. Here is the client code I've used to test , (both use WebClient
              | > and
              | > | HttpWebRequest ....) , the code work correctly on my test environment.
              | > |
              | > | =============== ==========
              | > | static void Main(string[] args)
              | > | {
              | > |
              | > |
              | > | DownloadByWebCl ient();
              | > |
              | > |
              | > | DownloadByHttpW ebRequest();
              | > | }
              | > |
              | > | static void DownloadByWebCl ient()
              | > | {
              | > | string url =
              | > | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
              | > | string clientfile = @"d:\temp\test_ webclient.pdf";
              | > |
              | > | WebClient wc = new WebClient();
              | > |
              | > | wc.DownloadFile (url,clientfile );
              | > |
              | > | }
              | > |
              | > | static void DownloadByHttpW ebRequest()
              | > | {
              | > | string url =
              | > | "http://localhost/StevenRoot/ControlWebApp/filedownload.as px";
              | > | string clientfile = @"d:\temp\test_ webrequest.pdf" ;
              | > |
              | > | HttpWebRequest req = WebRequest.Crea te(url) as HttpWebRequest;
              | > |
              | > | req.Method = "GET";
              | > | req.KeepAlive = true;
              | > |
              | > | HttpWebResponse rep = req.GetResponse () as HttpWebResponse ;
              | > |
              | > | Stream stream = rep.GetResponse Stream();
              | > |
              | > | FileStream fs = new FileStream(clie ntfile, FileMode.Create ,
              | > | FileAccess.Writ e);
              | > |
              | > | byte[] buf = new byte[1024];
              | > |
              | > | int i = 0;
              | > |
              | > | while( (i=stream.Read( buf,0,buf.Lengt h))> 0)
              | > | {
              | > | fs.Write(buf,0, i);
              | > | }
              | > |
              | > | fs.Close();
              | > |
              | > | stream.Close();
              | > |
              | > | rep.Close();
              | > |
              | > | }
              | > | =============== =============
              | > |
              | > | In addition, you can also try comment the below line in your
              serverside
              | > | code to see whether it helps:
              | > |
              | > | Response.Append Header("Content-Disposition", "attachment;fil ename=" +
              | > | fileID.ToString () + ".pdf");
              | > |
              | > | Thanks,
              | > |
              | > | Steven Cheng
              | > | Microsoft Online Support
              | > |
              | > | Get Secure! www.microsoft.com/security
              | > | (This posting is provided "AS IS", with no warranties, and confers no
              | > | rights.)
              | > |
              | > | --------------------
              | > | | From: "A.M-SG" <alanalan@newsg roup.nospam>
              | > | | References: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
              | > | <CXg1MTu3FHA.32 20@TK2MSFTNGXA0 1.phx.gbl>
              | > | | Subject: Re: System.Net.WebC lient.DownloadF ile doesn't work with
              http
              | > | attachments
              | > | | Date: Tue, 1 Nov 2005 08:15:42 -0500
              | > | | Lines: 124
              | > | | X-Priority: 3
              | > | | X-MSMail-Priority: Normal
              | > | | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
              | > | | X-RFC2646: Format=Flowed; Original
              | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
              | > | | Message-ID: <#Hcn3Yu3FHA.28 16@tk2msftngp13 .phx.gbl>
              | > | | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | > | | NNTP-Posting-Host: toronto-hse-ppp4253404.symp atico.ca 70.52.252.114
              | > | | Path:
              TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
              | > | | Xref: TK2MSFTNGXA01.p hx.gbl
              | > | microsoft.publi c.dotnet.langua ges.csharp:1331 23
              | > | | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | > | |
              | > | | Hi Steven,
              | > | |
              | > | | Firstly thank you for your reply.
              | > | |
              | > | | The code that you provided is not my question.
              | > | |
              | > | | My question is: "How to receive that pdf file at the client side?"
              | > | |
              | > | | The server side is done and it is similar to what you mentioned in
              | > your
              | > | | reply.
              | > | |
              | > | | I tried to receive the pdf file (test.pdf in your sample) by using
              | > | | System.Net.WebC lient.DownloadF ile, but it throws exception.
              | > | |
              | > | | Regards,
              | > | | Alan
              | > | |
              | > | |
              | > | |
              | > | | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
              | > | | news:CXg1MTu3FH A.3220@TK2MSFTN GXA01.phx.gbl.. .
              | > | | > Hi Alan,
              | > | | >
              | > | | > Welcome to MSDN newsgroup.
              | > | | > Regarding on the file downloading through WebClient class problem
              | > you
              | > | | > mentioned, seems a bit strange from a general view. It is
              possible a
              | > | | > machine specific issue. here is a test page's code which could be
              | > | | > correctly
              | > | | > used (let client user webbrowser or webclient class to download
              the
              | > | file)
              | > | | > on my side:
              | > | | >
              | > | | > =============== ===
              | > | | > private void Page_Load(objec t sender, System.EventArg s e)
              | > | | > {
              | > | | > Response.ClearH eaders();
              | > | | > Response.ClearC ontent();
              | > | | > Response.Conten tType = "applicatio n/octet-stream";
              | > | | >
              | > | | >
              | > |
              | >
              Response.Append Header("Content-Disposition","a ttachment;filen ame=test.pdf");
              | > | | >
              | > | | > Response.WriteF ile(Server.MapP ath("~/files/test.pdf"));
              | > | | >
              | > | | > Response.End();
              | > | | > }
              | > | | > =============== ===
              | > | | >
              | > | | > You can try the above code in your page to see whether it works.
              | > Also,
              | > | you
              | > | | > can run the webclient from multiple client to see whether it is
              | > client
              | > | | > specific.
              | > | | >
              | > | | > Thanks,
              | > | | >
              | > | | > Steven Cheng
              | > | | > Microsoft Online Support
              | > | | >
              | > | | > Get Secure! www.microsoft.com/security
              | > | | > (This posting is provided "AS IS", with no warranties, and
              confers
              | > no
              | > | | > rights.)
              | > | | >
              | > | | >
              | > | | >
              | > | | >
              | > | | > --------------------
              | > | | > | From: "A.M-SG" <alanalan@newsg roup.nospam>
              | > | | > | Subject: System.Net.WebC lient.DownloadF ile doesn't work with
              http
              | > | | > attachments
              | > | | > | Date: Mon, 31 Oct 2005 18:45:48 -0500
              | > | | > | Lines: 35
              | > | | > | X-Priority: 3
              | > | | > | X-MSMail-Priority: Normal
              | > | | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
              | > | | > | X-RFC2646: Format=Flowed; Original
              | > | | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
              | > | | > | Message-ID: <#Nwo3Un3FHA.36 00@TK2MSFTNGP12 .phx.gbl>
              | > | | > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | > | | > | NNTP-Posting-Host: hse-toronto-ppp3484752.symp atico.ca
              | > 65.92.97.129
              | > | | > | Path:
              | > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
              | > | | > | Xref: TK2MSFTNGXA01.p hx.gbl
              | > | | > microsoft.publi c.dotnet.langua ges.csharp:1330 60
              | > | | > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | > | | > |
              | > | | > | Hi,
              | > | | > |
              | > | | > | I have an aspx page at the web server that provides PDF
              documents
              | > for
              | > | | > smart
              | > | | > | client applications.
              | > | | > |
              | > | | > | Here is the code in aspx page that defines content type:
              | > | | > |
              | > | | > | Response.Conten tType = "applicatio n/octet-stream";
              | > | | > | Response.Append Header("Content-Disposition",
              | > "attachment;fil ename="
              | > +
              | > | | > | fileID.ToString () + ".pdf");
              | > | | > |
              | > | | > | I tested the aspx page by using browser and it works just fine.
              | > | | > |
              | > | | > | Now I need to receive that file by using the
              | > | | > | System.Net.WebC lient.DownloadF ile. The problem is that
              | > DownloadFile
              | > | | > method
              | > | | > | returns the following exception:
              | > | | > |
              | > | | > | "Unable to read data from the transport connection: The
              connection
              | > was
              | > | | > | closed."
              | > | | > |
              | > | | > | I tested the DownloadFile method to open a direct pdf file like
              | > the
              | > | | > | following statement:
              | > | | > |
              | > | | > | (new
              | > | | > |
              | > | | >
              | > |
              | >
              System.Net.WebC lient()).Downlo adFile(http://localhost/test.pdf,"c:\\t est.pdf
              | > | | > ");
              | > | | > |
              | > | | > | It works just fine.
              | > | | > |
              | > | | > | How can I use System.Net.WebC lient. DownloadFile to download
              http
              | > | | > | attachments?
              | > | | > |
              | > | | > | Any help would be apprecited,
              | > | | > | Alan
              | > | | > |
              | > | | > |
              | > | | > |
              | > | | >
              | > | |
              | > | |
              | > | |
              | > |
              | > |
              | >
              |
              |
              |

              Comment

              Working...