473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Streaming a file Thread Exceptions out

I have a web site where the user is able to download a file. I can't use an
anchor tag because I don't want the user to see where the filename is coming
from. Below is the code in which the user clicks to get the file. I could
swear this used to work but it definitely doesn't now. Each time at the
Response.End() method, I get a System.Threading.ThreadAbortException. I'm
not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileStream("c:\test.htm", IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(CType(fStream.Length, Int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=c:\test.htm")
fStream.Read(b, 0, CType(fStream.Length, Int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing
Nov 18 '05 #1
5 1432
Take the Response.End() out of it. That method raises the exception, and is
unnecessary. In fact, all of the clearing of the Response is also
unnecessary, unless you've already sent some of the Response.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
I have a web site where the user is able to download a file. I can't use an anchor tag because I don't want the user to see where the filename is coming from. Below is the code in which the user clicks to get the file. I could swear this used to work but it definitely doesn't now. Each time at the
Response.End() method, I get a System.Threading.ThreadAbortException. I'm
not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileStream("c:\test.htm", IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(CType(fStream.Length, Int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=c:\test.htm") fStream.Read(b, 0, CType(fStream.Length, Int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing

Nov 18 '05 #2
Kevin, I took out the .end method and much to my surprise, now it streams
the text of my index.aspx page. So for example, I am testing with a text
file called test.htm. It's content is only the word test. When my code bit
from below runs, the browser pops up a save/open dialogue. The file name
suggested is "index" with no known extension. If I save the file and open
it, I see the following

test
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>

etc.

My whole index.aspx is streamed.

Any ideas?

Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Take the Response.End() out of it. That method raises the exception, and is unnecessary. In fact, all of the clearing of the Response is also
unnecessary, unless you've already sent some of the Response.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
I have a web site where the user is able to download a file. I can't use
an
anchor tag because I don't want the user to see where the filename is

coming
from. Below is the code in which the user clicks to get the file. I

could
swear this used to work but it definitely doesn't now. Each time at the
Response.End() method, I get a System.Threading.ThreadAbortException.

I'm not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileStream("c:\test.htm", IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(CType(fStream.Length, Int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition",

"attachment;filename=c:\test.htm")
fStream.Read(b, 0, CType(fStream.Length, Int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing


Nov 18 '05 #3
Looks like you've still got some HTML in your Page Template (ASPX file). If
you remove everything but the @Page directive, it should be fine.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
Kevin, I took out the .end method and much to my surprise, now it streams
the text of my index.aspx page. So for example, I am testing with a text
file called test.htm. It's content is only the word test. When my code bit from below runs, the browser pops up a save/open dialogue. The file name
suggested is "index" with no known extension. If I save the file and open
it, I see the following

test
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>

etc.

My whole index.aspx is streamed.

Any ideas?

Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Take the Response.End() out of it. That method raises the exception, and

is
unnecessary. In fact, all of the clearing of the Response is also
unnecessary, unless you've already sent some of the Response.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
I have a web site where the user is able to download a file. I can't use
an
anchor tag because I don't want the user to see where the filename is

coming
from. Below is the code in which the user clicks to get the file. I

could
swear this used to work but it definitely doesn't now. Each time at the Response.End() method, I get a System.Threading.ThreadAbortException.

I'm not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileStream("c:\test.htm", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim b(CType(fStream.Length, Int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition",

"attachment;filename=c:\test.htm")
fStream.Read(b, 0, CType(fStream.Length, Int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing



Nov 18 '05 #4
Wow that doesn't make sense to me. My index.asp starts out like this

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb"
Inherits="filetransfer.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>
etc.

What are suggesting I remove? Most everything in the index.ASPX file is
HTML. But I don't thing that's what you meant.

Please check this thread back on Monday as I'm about to walk away from my PC
until then.

Thanks
Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Looks like you've still got some HTML in your Page Template (ASPX file). If you remove everything but the @Page directive, it should be fine.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
Kevin, I took out the .end method and much to my surprise, now it streams
the text of my index.aspx page. So for example, I am testing with a text file called test.htm. It's content is only the word test. When my code

bit
from below runs, the browser pops up a save/open dialogue. The file name suggested is "index" with no known extension. If I save the file and open it, I see the following

test
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>

etc.

My whole index.aspx is streamed.

Any ideas?

Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Take the Response.End() out of it. That method raises the exception, and
is
unnecessary. In fact, all of the clearing of the Response is also
unnecessary, unless you've already sent some of the Response.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
> I have a web site where the user is able to download a file. I
can't use
an
> anchor tag because I don't want the user to see where the filename
is coming
> from. Below is the code in which the user clicks to get the file. I could
> swear this used to work but it definitely doesn't now. Each time at

the > Response.End() method, I get a
System.Threading.ThreadAbortException. I'm
> not really sure why it is happening. Any clues?
> Eric
>
> Dim fStream As New System.IO.FileStream("c:\test.htm",

IO.FileMode.Open, > IO.FileAccess.Read, IO.FileShare.Read)
> Dim b(CType(fStream.Length, Int32)) As Byte
> Response.Clear()
> Response.ClearContent()
> Response.ClearHeaders()
> Response.ContentType = "application/unknown"
> Response.AddHeader("Content-Disposition",
"attachment;filename=c:\test.htm")
> fStream.Read(b, 0, CType(fStream.Length, Int32))
> Response.BinaryWrite(b)
> Response.End()
> fStream.Close()
> fStream = Nothing
>
>



Nov 18 '05 #5
> What are suggesting I remove? Most everything in the index.ASPX file is
HTML. But I don't thing that's what you meant.
That's what I meant. The HTML that VS.Net adds to your page is due to the
fact that an HTML document is what an ASPX page returns ALMOST all the time.
Streaming a file is one of the exceptions. In that case, you don't want any
additional content streamed to the browser; just what you send via your
code.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. .. Wow that doesn't make sense to me. My index.asp starts out like this

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb"
Inherits="filetransfer.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>
etc.

What are suggesting I remove? Most everything in the index.ASPX file is
HTML. But I don't thing that's what you meant.

Please check this thread back on Monday as I'm about to walk away from my PC until then.

Thanks
Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Looks like you've still got some HTML in your Page Template (ASPX file).

If
you remove everything but the @Page directive, it should be fine.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eric Sabine" <mo*****@hyottmail.com> wrote in message
news:3f***********************@news.twtelecom.net. ..
Kevin, I took out the .end method and much to my surprise, now it streams the text of my index.aspx page. So for example, I am testing with a text file called test.htm. It's content is only the word test. When my
code
bit
from below runs, the browser pops up a save/open dialogue. The file name suggested is "index" with no known extension. If I save the file and open it, I see the following

test
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>File Transferring Page</title>

etc.

My whole index.aspx is streamed.

Any ideas?

Eric

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
> Take the Response.End() out of it. That method raises the exception, and is
> unnecessary. In fact, all of the clearing of the Response is also
> unnecessary, unless you've already sent some of the Response.
>
> --
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
>
> "Eric Sabine" <mo*****@hyottmail.com> wrote in message
> news:3f***********************@news.twtelecom.net. ..
> > I have a web site where the user is able to download a file. I can't use
> an
> > anchor tag because I don't want the user to see where the filename is > coming
> > from. Below is the code in which the user clicks to get the file. I > could
> > swear this used to work but it definitely doesn't now. Each time
at the
> > Response.End() method, I get a

System.Threading.ThreadAbortException. I'm
> > not really sure why it is happening. Any clues?
> > Eric
> >
> > Dim fStream As New System.IO.FileStream("c:\test.htm",

IO.FileMode.Open,
> > IO.FileAccess.Read, IO.FileShare.Read)
> > Dim b(CType(fStream.Length, Int32)) As Byte
> > Response.Clear()
> > Response.ClearContent()
> > Response.ClearHeaders()
> > Response.ContentType = "application/unknown"
> > Response.AddHeader("Content-Disposition",
> "attachment;filename=c:\test.htm")
> > fStream.Read(b, 0, CType(fStream.Length, Int32))
> > Response.BinaryWrite(b)
> > Response.End()
> > fStream.Close()
> > fStream = Nothing
> >
> >
>
>



Nov 18 '05 #6

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

Similar topics

6
by: CJM | last post by:
I have a page which allows the user to open one of several spreadsheets by streaming the XLS to the client. On my development site, everything appears to work fine. On the live site, it works...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
22
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until...
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
8
by: Gabe Moothart | last post by:
Hi, I'm writing a windows service which interacts with a separate process. Basically, it calls a process which creates a file, and then my service reads that file. The problem is, the external...
3
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
5
by: pmakoi | last post by:
dear all this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic I am...
1
by: Faisal Shafiq | last post by:
I want to upload a file direct to the Silverlight Streaming Service from a Web Client such as silverlight application. As per our product requirement we want to upload a .WMV file directly from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.