473,651 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Threadin g.ThreadAbortEx ception. I'm
not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileS tream("c:\test. htm", IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(CType(fStream .Length, Int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=c:\test.h tm")
fStream.Read(b, 0, CType(fStream.L ength, Int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
Nov 18 '05 #1
5 1444
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*****@hyottm ail.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.Threadin g.ThreadAbortEx ception. I'm
not really sure why it is happening. Any clues?
Eric

Dim fStream As New System.IO.FileS tream("c:\test. htm", IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(CType(fStream .Length, Int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=c:\test.h tm") fStream.Read(b, 0, CType(fStream.L ength, Int32))
Response.Binary Write(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******** ******@TK2MSFTN GP10.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*****@hyottm ail.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.Threadin g.ThreadAbortEx ception.

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

Dim fStream As New System.IO.FileS tream("c:\test. htm", IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(CType(fStream .Length, Int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition",

"attachment;fil ename=c:\test.h tm")
fStream.Read(b, 0, CType(fStream.L ength, Int32))
Response.Binary Write(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*****@hyottm ail.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******** ******@TK2MSFTN GP10.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*****@hyottm ail.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.Threadin g.ThreadAbortEx ception.

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

Dim fStream As New System.IO.FileS tream("c:\test. htm", IO.FileMode.Ope n, IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(CType(fStream .Length, Int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition",

"attachment;fil ename=c:\test.h tm")
fStream.Read(b, 0, CType(fStream.L ength, Int32))
Response.Binary Write(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="ind ex.aspx.vb"
Inherits="filet ransfer.WebForm 1" %>
<!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******** ********@tk2msf tngp13.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*****@hyottm ail.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******** ******@TK2MSFTN GP10.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*****@hyottm ail.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.Threadin g.ThreadAbortEx ception. I'm
> not really sure why it is happening. Any clues?
> Eric
>
> Dim fStream As New System.IO.FileS tream("c:\test. htm",

IO.FileMode.Ope n, > IO.FileAccess.R ead, IO.FileShare.Re ad)
> Dim b(CType(fStream .Length, Int32)) As Byte
> Response.Clear( )
> Response.ClearC ontent()
> Response.ClearH eaders()
> Response.Conten tType = "applicatio n/unknown"
> Response.AddHea der("Content-Disposition",
"attachment;fil ename=c:\test.h tm")
> fStream.Read(b, 0, CType(fStream.L ength, Int32))
> Response.Binary Write(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*****@hyottm ail.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="ind ex.aspx.vb"
Inherits="filet ransfer.WebForm 1" %>
<!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******** ********@tk2msf tngp13.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*****@hyottm ail.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******** ******@TK2MSFTN GP10.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*****@hyottm ail.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.Threadin g.ThreadAbortEx ception. I'm
> > not really sure why it is happening. Any clues?
> > Eric
> >
> > Dim fStream As New System.IO.FileS tream("c:\test. htm",

IO.FileMode.Ope n,
> > IO.FileAccess.R ead, IO.FileShare.Re ad)
> > Dim b(CType(fStream .Length, Int32)) As Byte
> > Response.Clear( )
> > Response.ClearC ontent()
> > Response.ClearH eaders()
> > Response.Conten tType = "applicatio n/unknown"
> > Response.AddHea der("Content-Disposition",
> "attachment;fil ename=c:\test.h tm")
> > fStream.Read(b, 0, CType(fStream.L ength, Int32))
> > Response.Binary Write(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
3617
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 fine for the vast majority of users, but not for my colleague & I. When this page is called with the correct inputs, the standard Open/Save/Cancel/More Info dialog should appear. In the dialog, it gives the following details:
31
2483
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 tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is possible to break the task into some small ones (thread per fetch and processing thereafter or event...
22
5645
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 there is alot of data. In that case, the user will have to wait for the data to come back which may take a minute or so. I don't want the user to have to wait. Is it possible for javascript to periodically (while still receiving more data)...
18
20172
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 are created and detected before writing completes and so I cannot read them until the file handle used in their creation has been released. This would be easy to get around with file renaming or other file locking mechanisms which I could use...
8
26708
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 process can take a second or two to finish writing the file. If I try to read the file to soon, I get an exception that "The process cannot access the file because it is being used by another process". I could just set a timer, but the time it...
3
2331
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 must be the only method that users receive image files.
6
2714
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, every now and then the client would timeout and have to re-initiate the request... TIA!
5
3540
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 writing a web service that uses soap with attachments to send a large streaming data, The concept works quite well but when I started to test it I got this problem. When my client program calls a method that should return a real time data the...
1
2845
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 silverlight client to Silverlight streaming service. I tried to user WebClient and HttpWebRequest for that purpose but, unfortunately I can found the way to do so. There are some problems with both classes. 1. There is no property of get...
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7297
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1587
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.