473,480 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange download problem!

Hi! everybody,

I'm facing a quite strange download problem. I use the following code to
download an XML file to client side:

With Response
' clear buffer
Call .Clear()

' specify the type of the downloadable file
.ContentType = "application/octet-stream" ' I have
also tried to change this statement to Response.ContentType = "Text/XML"
, but the result is same

' det the default filename in the FileDownload dialog box
Call .AddHeader("Content-Disposition", "attachment;
filename=""Download.XML""")

' force to flush buffer
Call .Flush()

' download the file
Call .WriteFile("Original.XML")
End With

When the download is finished, I found that some HTML code are attached to
the end of my original XML statements in download file. The HTML code is
what exact the form just before download. I would like to know what causes
this result and the solution. Certainly, I need the XML content only.

Thanks for your attention and kindly advice!

Regards,
James
Nov 18 '05 #1
14 1861
One suggestion, try Response.Write(file) instead of writefile, that may cure
the ailment.

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Hi! everybody,

I'm facing a quite strange download problem. I use the following code to
download an XML file to client side:

With Response
' clear buffer
Call .Clear()

' specify the type of the downloadable file
.ContentType = "application/octet-stream" ' I have
also tried to change this statement to Response.ContentType = "Text/XML"
, but the result is same

' det the default filename in the FileDownload dialog box
Call .AddHeader("Content-Disposition", "attachment;
filename=""Download.XML""")

' force to flush buffer
Call .Flush()

' download the file
Call .WriteFile("Original.XML")
End With

When the download is finished, I found that some HTML code are attached to
the end of my original XML statements in download file. The HTML code is
what exact the form just before download. I would like to know what causes this result and the solution. Certainly, I need the XML content only.

Thanks for your attention and kindly advice!

Regards,
James

Nov 18 '05 #2
Alvin,

Thanks for your response. But even I change it to Response.Write, the
strange behavior still be there.

Regards,
James

"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > ¦b¶l¥ó
news:eb**************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
One suggestion, try Response.Write(file) instead of writefile, that may cure the ailment.

Nov 18 '05 #3
Hello James,

Thanks for posting in the group.

Please try adding Call.End() before "End With" to see if it works.

I used the following code and it works great for me:

string filename = "C:\MyFolder\MyFile.xml";
System.IO.FileInfo file = new System.IO.FileInfo(fileName);
Response.Clear(); // clear the current output content from the buffer
Response.AppendHeader("Content-Disposition", "attachment; filename=" +
file.Name);
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();

Does that answer your question? If the problem is still there, please feel
free to post here.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #4
SSW
After call Call .WriteFile("Original.XML") type
Response.End();
Will work.
Thanks,

sswalia
MCSD, MCAD, OCA
"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Hi! everybody,

I'm facing a quite strange download problem. I use the following code to
download an XML file to client side:

With Response
' clear buffer
Call .Clear()

' specify the type of the downloadable file
.ContentType = "application/octet-stream" ' I have
also tried to change this statement to Response.ContentType = "Text/XML"
, but the result is same

' det the default filename in the FileDownload dialog box
Call .AddHeader("Content-Disposition", "attachment;
filename=""Download.XML""")

' force to flush buffer
Call .Flush()

' download the file
Call .WriteFile("Original.XML")
End With

When the download is finished, I found that some HTML code are attached to
the end of my original XML statements in download file. The HTML code is
what exact the form just before download. I would like to know what causes this result and the solution. Certainly, I need the XML content only.

Thanks for your attention and kindly advice!

Regards,
James

Nov 18 '05 #5
Hi! Yanhong and SSW,

Thanks for your reply! I works by adding Call .End() and solve my problem.

However, there is a side-effect by doing so. Threading.ThreadAbortException
is fired once the .End() method is called. My workround is to handle this
exception and put all remaining statements after the .End() method under
this exception handling routine. Do you have a better idea to overcome this
side-effect?

Anyway, thanks for your effort!

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:PF**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
Hello James,

Thanks for posting in the group.

Please try adding Call.End() before "End With" to see if it works.

I used the following code and it works great for me:

string filename = "C:\MyFolder\MyFile.xml";
System.IO.FileInfo file = new System.IO.FileInfo(fileName);
Response.Clear(); // clear the current output content from the buffer
Response.AppendHeader("Content-Disposition", "attachment; filename=" +
file.Name);
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();

Does that answer your question? If the problem is still there, please feel
free to post here.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #6
Hello

Put the remaining state after the .End() statement. The .NET Framework will
handle the ThreadAbortException

Best regards
Sherif

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:#m**************@TK2MSFTNGP12.phx.gbl...
Hi! Yanhong and SSW,

Thanks for your reply! I works by adding Call .End() and solve my problem.
However, there is a side-effect by doing so. Threading.ThreadAbortException is fired once the .End() method is called. My workround is to handle this
exception and put all remaining statements after the .End() method under
this exception handling routine. Do you have a better idea to overcome this side-effect?

Anyway, thanks for your effort!

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:PF**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
Hello James,

Thanks for posting in the group.

Please try adding Call.End() before "End With" to see if it works.

I used the following code and it works great for me:

string filename = "C:\MyFolder\MyFile.xml";
System.IO.FileInfo file = new System.IO.FileInfo(fileName);
Response.Clear(); // clear the current output content from the buffer
Response.AppendHeader("Content-Disposition", "attachment; filename=" +
file.Name);
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();

Does that answer your question? If the problem is still there, please feel free to post here.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

rights.


Nov 18 '05 #7
Hello, Sherif,

I have my own exceptional handler which handles all unexpected exceptions.
So if I don't handle it, this exception will fire my default exceptional
handling routine which logs exception details in my self-defined log and
also sends an e-mail to me. That's why I have to handle it. Do you think
there is other better workaround?

Regards,
James

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> ¦b¶l¥ó
news:es**************@TK2MSFTNGP11.phx.gbl ¤¤¼¶¼g...
Hello

Put the remaining state after the .End() statement. The .NET Framework will handle the ThreadAbortException

Best regards
Sherif

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:#m**************@TK2MSFTNGP12.phx.gbl...
Hi! Yanhong and SSW,

Thanks for your reply! I works by adding Call .End() and solve my

problem.

However, there is a side-effect by doing so.

Threading.ThreadAbortException
is fired once the .End() method is called. My workround is to handle this
exception and put all remaining statements after the .End() method under
this exception handling routine. Do you have a better idea to overcome

this
side-effect?

Anyway, thanks for your effort!

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:PF**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
Hello James,

Thanks for posting in the group.

Please try adding Call.End() before "End With" to see if it works.

I used the following code and it works great for me:

string filename = "C:\MyFolder\MyFile.xml";
System.IO.FileInfo file = new System.IO.FileInfo(fileName);
Response.Clear(); // clear the current output content from the buffer
Response.AppendHeader("Content-Disposition", "attachment; filename=" +
file.Name);
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();

Does that answer your question? If the problem is still there, please

feel free to post here.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

rights.



Nov 18 '05 #8
Hello

ThreadAbortException is special in that even if your handler catches it, it
will be rethrown again at the end of the catch block, unless you call
Thread.ResetAbort(). In your case it is not appropriate to call
ResetAbort(), because this means the rendering of the page will continue.
If you don't want to call Response.End() which throws the
ThreadAbortException, you can override the Render Method and not call the
base class Render method.

Best regards
Sherif

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:eJ**************@tk2msftngp13.phx.gbl...
Hello, Sherif,

I have my own exceptional handler which handles all unexpected exceptions.
So if I don't handle it, this exception will fire my default exceptional
handling routine which logs exception details in my self-defined log and
also sends an e-mail to me. That's why I have to handle it. Do you think
there is other better workaround?

Regards,
James

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> ¦b¶l¥ó
news:es**************@TK2MSFTNGP11.phx.gbl ¤¤¼¶¼g...
Hello

Put the remaining state after the .End() statement. The .NET Framework

will
handle the ThreadAbortException

Best regards
Sherif

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:#m**************@TK2MSFTNGP12.phx.gbl...
Hi! Yanhong and SSW,

Thanks for your reply! I works by adding Call .End() and solve my

problem.

However, there is a side-effect by doing so.

Threading.ThreadAbortException
is fired once the .End() method is called. My workround is to handle this exception and put all remaining statements after the .End() method under this exception handling routine. Do you have a better idea to overcome
this
side-effect?

Anyway, thanks for your effort!

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:PF**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
> Hello James,
>
> Thanks for posting in the group.
>
> Please try adding Call.End() before "End With" to see if it works.
>
> I used the following code and it works great for me:
>
> string filename = "C:\MyFolder\MyFile.xml";
> System.IO.FileInfo file = new System.IO.FileInfo(fileName);
> Response.Clear(); // clear the current output content from the
buffer > Response.AppendHeader("Content-Disposition", "attachment; filename=" + > file.Name);
> Response.AppendHeader("Content-Length", file.Length.ToString());
> Response.ContentType = "application/octet-stream";
> Response.WriteFile(file.FullName);
> Response.End();
>
> Does that answer your question? If the problem is still there,

please feel
> free to post here.
>
> Best regards,
> Yanhong Huang
> Microsoft Online Partner Support
>
> Get Secure! ¨C www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>



Nov 18 '05 #9
Hello James,

Thanks for your response.

The Response.End method ends the page execution and shifts the execution to
the Application_EndRequest event in the application's event pipeline. The
line of code that follows Response.End is not executed. So
ThreadAbortException exception occurs.

To work around this problem, For Response.End, call the
ApplicationInstance.CompleteRequest method instead of Response.End to
bypass the code execution to the Application_EndRequest event.

For detailed info on it, please refer to MSDN article:
"PRB: ThreadAbortException Occurs If You Use Response.End,
Response.Redirect, or Server.Transfer"
http://support.microsoft.com/?id=312629

Does that answer your questoin?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #10
Hello Yan-Hong,

Thanks for you reply again!

I think this is a quite interesting case since when I use
ApplicationInstance.CompleteRequest instead of Response.End, no more
exception is captured. However, the original problem, HTML codes are
included in the downloaded file, comes again!

Until now, I think using Reponse.End with additional exceptional handler (in
which the remaining codes after Response.End are there) may be the best way
to solve my problem.

If you have any other good idea, please let me know and share with all
others here.

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:Yx**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
Hello James,

Thanks for your response.

The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The
line of code that follows Response.End is not executed. So
ThreadAbortException exception occurs.

To work around this problem, For Response.End, call the
ApplicationInstance.CompleteRequest method instead of Response.End to
bypass the code execution to the Application_EndRequest event.

For detailed info on it, please refer to MSDN article:
"PRB: ThreadAbortException Occurs If You Use Response.End,
Response.Redirect, or Server.Transfer"
http://support.microsoft.com/?id=312629

Does that answer your questoin?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #11
Hello Sherif,

Thanks again for your reply!

Do you mean that I should put all remaining codes outside the
Try...Catch...End Try block? On the other hand, I don't understand what
class's Render method you suggest me to override.

Regards,
James

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> ¦b¶l¥ó
news:OO**************@TK2MSFTNGP11.phx.gbl ¤¤¼¶¼g...
Hello

ThreadAbortException is special in that even if your handler catches it, it will be rethrown again at the end of the catch block, unless you call
Thread.ResetAbort(). In your case it is not appropriate to call
ResetAbort(), because this means the rendering of the page will continue.
If you don't want to call Response.End() which throws the
ThreadAbortException, you can override the Render Method and not call the
base class Render method.

Best regards
Sherif

Nov 18 '05 #12
Hi James,

Just now I found this good article for you. :)

It contains a good sample in ASP.NET on how to download and upload file.

"Downloading and Uploading Files"
http://msdn.microsoft.com/library/en...mig-downloadin
ganduploading.asp?frame=true#aspnet-jspmig-downloadinganduploading_topic6

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #13
Hi Yan-Hong,

Thanks again for your effort on my problem. I'll study the document to
solve my problem.

Regards,
James

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> ¦b¶l¥ó
news:Cj**************@cpmsftngxa06.phx.gbl ¤¤¼¶¼g...
Hi James,

Just now I found this good article for you. :)

It contains a good sample in ASP.NET on how to download and upload file.

"Downloading and Uploading Files"
http://msdn.microsoft.com/library/en...mig-downloadin ganduploading.asp?frame=true#aspnet-jspmig-downloadinganduploading_topic6

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #14
Hi James,

It is my pleasure. :)

Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

Nov 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3993
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem...
1
3933
by: Daniel Cardoso | last post by:
I don't know what else to try - In my asp.net app, when the file name has Windows-1252 characters (like ã and ç), these characters appear, each one, as two strange characters in the file name label...
8
6667
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
7
1428
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly...
2
218
by: Flurry | last post by:
Hello I've got a problem and I'm not getting much help trying to resolve it. I've searched google all morning for an answer.... I have the following code: Lab1.text = "Your Serial Number...
3
2606
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm...
1
1882
by: Blackstar | last post by:
I have a website I am trying to download a file from. This website is strange in the fact that there is no direct link to the URL of the file. The way the site works is as follows: 1) Enter in...
4
2604
by: David | last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage at work (it's an internal page on my company's intranet). The page produces a runtime error after a while and the...
0
811
by: aepheus | last post by:
I use the following code to create a file for the user to download: Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Buffer = true; Response.ContentType = "text/ris";...
0
7057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5357
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.