Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Saturday, March 24, 2012

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.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename=test.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.WebClient.DownloadFile. 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.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf
");
It works just fine.
How can I use System.Net.WebClient. DownloadFile to download http
attachments?
Any help would be apprecited,
AlanThe answer is in your question, but you may not recognize it.
An HTTP Request is for a single resource, identified by the URL of the
resource, or in the case of the WebClient, a URI plus a file descriptor. You
have an ASPX page that returns a file with a couple of special Response
Headers in it. Those Response Headers read:
Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");
This header indicates that the client should prompt the client to make a
second request for the file descriptor specified (text.pdf), and that the
Content-Type of that file is binary.
So, what you have to do is read the Response Headers, and make a second
request for that file specified.
IETF RFC 1806 has a detailed explanation of this Response Header:
http://www.ietf.org/rfc/rfc1806.txt
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.
"A.M-SG" <alanalan@.newsgroup.nospam> wrote in message
news:eY7l5Zu3FHA.1148@.tk2msftngp13.phx.gbl...
> 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.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=test.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.WebClient.DownloadFile. 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.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.p
df");
> It works just fine.
> How can I use System.Net.WebClient. DownloadFile to download http
> attachments?
> Any help would be apprecited,
> Alan
>

System.Net.WebClient.DownloadFile doesnt 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.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename=test.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.WebClient.DownloadFile. 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.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf");

It works just fine.

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

Any help would be apprecited,
AlanThe answer is in your question, but you may not recognize it.

An HTTP Request is for a single resource, identified by the URL of the
resource, or in the case of the WebClient, a URI plus a file descriptor. You
have an ASPX page that returns a file with a couple of special Response
Headers in it. Those Response Headers read:

Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");

This header indicates that the client should prompt the client to make a
second request for the file descriptor specified (text.pdf), and that the
Content-Type of that file is binary.

So, what you have to do is read the Response Headers, and make a second
request for that file specified.

IETF RFC 1806 has a detailed explanation of this Response Header:

http://www.ietf.org/rfc/rfc1806.txt

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"A.M-SG" <alanalan@.newsgroup.nospam> wrote in message
news:eY7l5Zu3FHA.1148@.tk2msftngp13.phx.gbl...
> 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.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=test.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.WebClient.DownloadFile. 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.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf");
> It works just fine.
> How can I use System.Net.WebClient. DownloadFile to download http
> attachments?
> Any help would be apprecited,
> Alan

Tuesday, March 13, 2012

System.Runtime.InteropServices.COMException

Hi all,
when i try to access the pdf file from one of the network drive, i am
getthing this problem. it seems it folder permission problem. dont know how
to solve this. i am using Windows XP prof. do you have any idea how to solve
this prob.
thanks
bala
error message:
Unable to find GhostScript. Draw File:
File={\\tk00\Samples\03-06-01\04-1234-4.pdf} Parameters={image=1}
Canvas={Width=0 Height=0 Depth=32 Buffer=0}
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Unable to
find GhostScript. Draw File: File={\\tk00\Samples\03-06-01\04-1234-4.pdf}
Parameters={image=1} Canvas={Width=0 Height=0 Depth=32 Buffer=0}
Source Error:
Line 142: Dim ca As New WebSupergoo.ImageGlue5.Canvas
Line 143:
Line 144: ca.DrawFile(sPath, "image=1") 'get page = 1
Line 145: ImgURL1 = SessionURL & "/a-1.gif"
Line 146: ImgPath1 = Servertypically the asp.net account doesn't have network permissions. checnge to a
domain account with network permission or is iis 6.0, use an appool
-- bruce (sqlwork.com)
"Bala" <Bala@.discussions.microsoft.com> wrote in message
news:FD73C8B5-3F06-4A0E-B0D3-9C6B796FE0AD@.microsoft.com...
> Hi all,
> when i try to access the pdf file from one of the network drive, i am
> getthing this problem. it seems it folder permission problem. dont know
> how
> to solve this. i am using Windows XP prof. do you have any idea how to
> solve
> this prob.
> thanks
> bala
> error message:
> Unable to find GhostScript. Draw File:
> File={\\tk00\Samples\03-06-01\04-1234-4.pdf} Parameters={image=1}
> Canvas={Width=0 Height=0 Depth=32 Buffer=0}
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Runtime.InteropServices.COMException: Unable to
> find GhostScript. Draw File: File={\\tk00\Samples\03-06-01\04-1234-4.pdf}
> Parameters={image=1} Canvas={Width=0 Height=0 Depth=32 Buffer=0}
> Source Error:
> Line 142: Dim ca As New WebSupergoo.ImageGlue5.Canvas
> Line 143:
> Line 144: ca.DrawFile(sPath, "image=1") 'get page = 1
> Line 145: ImgURL1 = SessionURL & "/a-1.gif"
> Line 146: ImgPath1 = Server
>

System.Runtime.InteropServices.COMException

Hi all,

when i try to access the pdf file from one of the network drive, i am
getthing this problem. it seems it folder permission problem. dont know how
to solve this. i am using windows xp prof. do you have any idea how to solve
this prob.

thanks
bala

error message:

Unable to find GhostScript. Draw File:
File={\\tk00\Samples\03-06-01\04-1234-4.pdf} Parameters={image=1}
Canvas={Width=0 Height=0 Depth=32 Buffer=0}
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Unable to
find GhostScript. Draw File: File={\\tk00\Samples\03-06-01\04-1234-4.pdf}
Parameters={image=1} Canvas={Width=0 Height=0 Depth=32 Buffer=0}

Source Error:

Line 142: Dim ca As New WebSupergoo.ImageGlue5.Canvas
Line 143:
Line 144: ca.DrawFile(sPath, "image=1") 'get page = 1
Line 145: ImgURL1 = SessionURL & "/a-1.gif"
Line 146: ImgPath1 = Servertypically the asp.net account doesn't have network permissions. checnge to a
domain account with network permission or is iis 6.0, use an appool

-- bruce (sqlwork.com)

"Bala" <Bala@.discussions.microsoft.com> wrote in message
news:FD73C8B5-3F06-4A0E-B0D3-9C6B796FE0AD@.microsoft.com...
> Hi all,
> when i try to access the pdf file from one of the network drive, i am
> getthing this problem. it seems it folder permission problem. dont know
> how
> to solve this. i am using windows xp prof. do you have any idea how to
> solve
> this prob.
> thanks
> bala
> error message:
> Unable to find GhostScript. Draw File:
> File={\\tk00\Samples\03-06-01\04-1234-4.pdf} Parameters={image=1}
> Canvas={Width=0 Height=0 Depth=32 Buffer=0}
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Runtime.InteropServices.COMException: Unable to
> find GhostScript. Draw File: File={\\tk00\Samples\03-06-01\04-1234-4.pdf}
> Parameters={image=1} Canvas={Width=0 Height=0 Depth=32 Buffer=0}
> Source Error:
> Line 142: Dim ca As New WebSupergoo.ImageGlue5.Canvas
> Line 143:
> Line 144: ca.DrawFile(sPath, "image=1") 'get page = 1
> Line 145: ImgURL1 = SessionURL & "/a-1.gif"
> Line 146: ImgPath1 = Server