473,545 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

context.Respons e.OutputStream. Write(buffer, 0, count) questions

trying to understand the below shown code.
After this is run the browser opens a file-save dialog box for saving the
file.
I wonder how it knows I want the file saved?

But more important, the dialog box has as the default file name the name of
this ashx file.

I'd like to make that name more meaningfull but don't know how it gets set.
I'm looking for a Response.Write but don't find one. Maybe that why the
funny default filename?

Got a clue as to how that gets set?

Also, I see the content.Request below. Looks like a chance for the user to
request different size images. But I don't see anything happening when I run
the code!

Do you know what that code should be accomplishing?

I read the help for IHttpHandler ProcessRequest but that didn't help me

Thanks for any help at all

Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.Pr ocessRequest

' Set up the response settings

context.Respons e.ContentType = "image/jpeg"

context.Respons e.Cache.SetCach eability(HttpCa cheability.Publ ic)

context.Respons e.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Origi nal

Select Case context.Request .QueryString("S ize")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Mediu m

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Origi nal

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

If ((Not (context.Reques t.QueryString(" PhotoID")) Is Nothing) _

AndAlso (context.Reques t.QueryString(" PhotoID") <"")) Then

id = [Convert].ToInt32(contex t.Request.Query String("PhotoID "))

stream = PhotoManager.Ge tPhoto(id, size)

Else

id = [Convert].ToInt32(contex t.Request.Query String("AlbumID "))

stream = PhotoManager.Ge tFirstPhoto(id, size)

End If

' Get the photo from the database, if nothing is returned, get the default
"placeholde r" photo

If (stream Is Nothing) Then

stream = PhotoManager.Ge tPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

Dim buffer() As Byte = New Byte((buffersiz e) - 1) {}

Dim count As Integer = stream.Read(buf fer, 0, buffersize)
Do While (count 0)

context.Respons e.OutputStream. Write(buffer, 0, count)

count = stream.Read(buf fer, 0, buffersize)
Loop

End Sub
Nov 13 '08 #1
4 11936
Here you go
http://support.microsoft.com/kb/260519/EN-US/

Basically this is the line you need to add
Response.AddHea der "content-disposition","a ttachment; filename=fname. ext"
where fname.ext is the file name you want it to be....

George.
"AAaron123" <aa*******@road runner.comwrote in message
news:eo******** ******@TK2MSFTN GP03.phx.gbl...
trying to understand the below shown code.
After this is run the browser opens a file-save dialog box for saving the
file.
I wonder how it knows I want the file saved?

But more important, the dialog box has as the default file name the name
of this ashx file.

I'd like to make that name more meaningfull but don't know how it gets
set. I'm looking for a Response.Write but don't find one. Maybe that why
the funny default filename?

Got a clue as to how that gets set?

Also, I see the content.Request below. Looks like a chance for the user to
request different size images. But I don't see anything happening when I
run the code!

Do you know what that code should be accomplishing?

I read the help for IHttpHandler ProcessRequest but that didn't help me

Thanks for any help at all

Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.Pr ocessRequest

' Set up the response settings

context.Respons e.ContentType = "image/jpeg"

context.Respons e.Cache.SetCach eability(HttpCa cheability.Publ ic)

context.Respons e.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Origi nal

Select Case context.Request .QueryString("S ize")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Mediu m

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Origi nal

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

If ((Not (context.Reques t.QueryString(" PhotoID")) Is Nothing) _

AndAlso (context.Reques t.QueryString(" PhotoID") <"")) Then

id = [Convert].ToInt32(contex t.Request.Query String("PhotoID "))

stream = PhotoManager.Ge tPhoto(id, size)

Else

id = [Convert].ToInt32(contex t.Request.Query String("AlbumID "))

stream = PhotoManager.Ge tFirstPhoto(id, size)

End If

' Get the photo from the database, if nothing is returned, get the default
"placeholde r" photo

If (stream Is Nothing) Then

stream = PhotoManager.Ge tPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

Dim buffer() As Byte = New Byte((buffersiz e) - 1) {}

Dim count As Integer = stream.Read(buf fer, 0, buffersize)
Do While (count 0)

context.Respons e.OutputStream. Write(buffer, 0, count)

count = stream.Read(buf fer, 0, buffersize)
Loop

End Sub

Nov 13 '08 #2
That's interesting, because the code did not contain that statement, as the
site suggested it should.
And it worked except for the crazy filename in the dialog box.
Do you think the context.Respons e.ContentType = "image/jpeg" line caused the
dialog box to open?

I see in the code lines like:
zz=context.Requ est.QueryString ("Size")

So, just to see, I tried:
Dim s As String = context.Request .QueryString("F ilename")

which of course doesn't work.

Am I close?

Is there something that does work to get the filename?

Thanks for the info

"George" <no*****@comcas t.netwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Here you go
http://support.microsoft.com/kb/260519/EN-US/

Basically this is the line you need to add
Response.AddHea der "content-disposition","a ttachment; filename=fname. ext"
where fname.ext is the file name you want it to be....

George.
"AAaron123" <aa*******@road runner.comwrote in message
news:eo******** ******@TK2MSFTN GP03.phx.gbl...
>trying to understand the below shown code.
After this is run the browser opens a file-save dialog box for saving the
file.
I wonder how it knows I want the file saved?

But more important, the dialog box has as the default file name the name
of this ashx file.

I'd like to make that name more meaningfull but don't know how it gets
set. I'm looking for a Response.Write but don't find one. Maybe that why
the funny default filename?

Got a clue as to how that gets set?

Also, I see the content.Request below. Looks like a chance for the user
to request different size images. But I don't see anything happening when
I run the code!

Do you know what that code should be accomplishing?

I read the help for IHttpHandler ProcessRequest but that didn't help me

Thanks for any help at all

Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.P rocessRequest

' Set up the response settings

context.Respon se.ContentType = "image/jpeg"

context.Respon se.Cache.SetCac heability(HttpC acheability.Pub lic)

context.Respon se.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Origi nal

Select Case context.Request .QueryString("S ize")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Mediu m

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Origi nal

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

If ((Not (context.Reques t.QueryString(" PhotoID")) Is Nothing) _

AndAlso (context.Reques t.QueryString(" PhotoID") <"")) Then

id = [Convert].ToInt32(contex t.Request.Query String("PhotoID "))

stream = PhotoManager.Ge tPhoto(id, size)

Else

id = [Convert].ToInt32(contex t.Request.Query String("AlbumID "))

stream = PhotoManager.Ge tFirstPhoto(id, size)

End If

' Get the photo from the database, if nothing is returned, get the
default "placeholde r" photo

If (stream Is Nothing) Then

stream = PhotoManager.Ge tPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

Dim buffer() As Byte = New Byte((buffersiz e) - 1) {}

Dim count As Integer = stream.Read(buf fer, 0, buffersize)
Do While (count 0)

context.Respon se.OutputStream .Write(buffer, 0, count)

count = stream.Read(buf fer, 0, buffersize)
Loop

End Sub


Nov 13 '08 #3
you need to study the http protocol more closely. a web response has headers
and content. for what you are doing there are two header. "content-type"
which defines the what is being returnd (in your case a jpeg).

the default file name in save dialog for a browser is the name of the
request. you can alter this with the "content-disposition" header.

Response.AddHea der("content-disposition","a ttachment; filename=myImg. jpg");

-- bruce (sqlwork.com)
"AAaron123" wrote:
trying to understand the below shown code.
After this is run the browser opens a file-save dialog box for saving the
file.
I wonder how it knows I want the file saved?

But more important, the dialog box has as the default file name the name of
this ashx file.

I'd like to make that name more meaningfull but don't know how it gets set.
I'm looking for a Response.Write but don't find one. Maybe that why the
funny default filename?

Got a clue as to how that gets set?

Also, I see the content.Request below. Looks like a chance for the user to
request different size images. But I don't see anything happening when I run
the code!

Do you know what that code should be accomplishing?

I read the help for IHttpHandler ProcessRequest but that didn't help me

Thanks for any help at all

Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.Pr ocessRequest

' Set up the response settings

context.Respons e.ContentType = "image/jpeg"

context.Respons e.Cache.SetCach eability(HttpCa cheability.Publ ic)

context.Respons e.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Origi nal

Select Case context.Request .QueryString("S ize")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Mediu m

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Origi nal

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

If ((Not (context.Reques t.QueryString(" PhotoID")) Is Nothing) _

AndAlso (context.Reques t.QueryString(" PhotoID") <"")) Then

id = [Convert].ToInt32(contex t.Request.Query String("PhotoID "))

stream = PhotoManager.Ge tPhoto(id, size)

Else

id = [Convert].ToInt32(contex t.Request.Query String("AlbumID "))

stream = PhotoManager.Ge tFirstPhoto(id, size)

End If

' Get the photo from the database, if nothing is returned, get the default
"placeholde r" photo

If (stream Is Nothing) Then

stream = PhotoManager.Ge tPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

Dim buffer() As Byte = New Byte((buffersiz e) - 1) {}

Dim count As Integer = stream.Read(buf fer, 0, buffersize)
Do While (count 0)

context.Respons e.OutputStream. Write(buffer, 0, count)

count = stream.Read(buf fer, 0, buffersize)
Loop

End Sub
Nov 13 '08 #4

"bruce barker" <br*********@di scussions.micro soft.comwrote in message
news:C0******** *************** ***********@mic rosoft.com...
you need to study the http protocol more closely. a web response has
headers
That suggestion was helpful. I googled "http protocol", read it, then read
about QueryString and ran a little code and it looks like the request
contains only an image number and the size. So in your future replies please
continue to point people to what they should read about. Now I have to find
out what caused the request and what determins what is included. I think I
know where to look.

thanks

and content. for what you are doing there are two header. "content-type"
which defines the what is being returnd (in your case a jpeg).

the default file name in save dialog for a browser is the name of the
request. you can alter this with the "content-disposition" header.

Response.AddHea der("content-disposition","a ttachment;
filename=myImg. jpg");

-- bruce (sqlwork.com)
"AAaron123" wrote:
>trying to understand the below shown code.
After this is run the browser opens a file-save dialog box for saving the
file.
I wonder how it knows I want the file saved?

But more important, the dialog box has as the default file name the name
of
this ashx file.

I'd like to make that name more meaningfull but don't know how it gets
set.
I'm looking for a Response.Write but don't find one. Maybe that why the
funny default filename?

Got a clue as to how that gets set?

Also, I see the content.Request below. Looks like a chance for the user
to
request different size images. But I don't see anything happening when I
run
the code!

Do you know what that code should be accomplishing?

I read the help for IHttpHandler ProcessRequest but that didn't help me

Thanks for any help at all

Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.P rocessRequest

' Set up the response settings

context.Respon se.ContentType = "image/jpeg"

context.Respon se.Cache.SetCac heability(HttpC acheability.Pub lic)

context.Respon se.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Origi nal

Select Case context.Request .QueryString("S ize")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Mediu m

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Origi nal

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

If ((Not (context.Reques t.QueryString(" PhotoID")) Is Nothing) _

AndAlso (context.Reques t.QueryString(" PhotoID") <"")) Then

id = [Convert].ToInt32(contex t.Request.Query String("PhotoID "))

stream = PhotoManager.Ge tPhoto(id, size)

Else

id = [Convert].ToInt32(contex t.Request.Query String("AlbumID "))

stream = PhotoManager.Ge tFirstPhoto(id, size)

End If

' Get the photo from the database, if nothing is returned, get the
default
"placeholder " photo

If (stream Is Nothing) Then

stream = PhotoManager.Ge tPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

Dim buffer() As Byte = New Byte((buffersiz e) - 1) {}

Dim count As Integer = stream.Read(buf fer, 0, buffersize)
Do While (count 0)

context.Respon se.OutputStream .Write(buffer, 0, count)

count = stream.Read(buf fer, 0, buffersize)
Loop

End Sub

Nov 13 '08 #5

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

Similar topics

0
2577
by: Copa | last post by:
Hello, I am testing buffering an asp page and Flushing information out to the browser, hence i wrote the code in an asp page that follows this Message Post. The loops are suppose to simulate long search processes with a flush after each search. When i Navigate to the page, redirect to it from another page, or type the URL to this page in...
3
17309
by: Brian Piotrowski | last post by:
Hi All, I'm trying to run a simple query from an ASP page. I want the query to select each individual field in a table and compare it to another table. If the value doesn't exist, I want it reported. Here's the code I have to do this check: 'Check to see if there are any assemblies not in the database! strSQL = "select...
7
6348
by: Stephanie | last post by:
If response.buffer is set to true, and no response.flush has been executed, is it accurate to expect that my browser should not be rendering the content which I (well Ok, someone else) is sending in response.write statements? Thanks.
0
1842
by: abraham | last post by:
Hi In an .aspx codebehind file I retrieve a file from a database and write it to the response buffer, so the browser pops up a 'save file' dialog and the user can save the file to disk. The relevant part of the code (VB) that does this is listed below: Response.Buffer = True Response.Clear()
0
2049
by: Brian Piotrowski | last post by:
Hi All, I have an SQL Server 2000 table that contains less than 2000 records. I would like to select some of these records and group them. The query I wrote runs fine in SQL Server's Query Analyzer, but when I run it in an ASP page, I get: Response object error 'ASP 0251 : 80004005'
1
1781
by: Brian Piotrowski | last post by:
Hi All, I'm trying to run a simple query from an ASP page. I want the query to select each individual field in a table and compare it to another table. If the value doesn't exist, I want it reported. Here's the code I have to do this check: 'Check to see if there are any assemblies not in the database! strSQL = "select...
12
7877
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug it, it works every time! I even set it to True, but did a .Flush just before the error, and the error won't happen. It only happens when...
1
6307
by: Gurpal | last post by:
I'm getting this error when I test this page. Here is the error: Response object error 'ASP 0251 : 80004005' Response Buffer Limit Exceeded /test/test4.asp, line 0 Execution of the ASP page caused the Response Buffer to exceed its configured limit.
0
1886
by: Anthony Jones | last post by:
"DR" <softwareengineer98037@yahoo.comwrote in message news:ebCg7zR8IHA.1200@TK2MSFTNGP04.phx.gbl... of Please don't multi-post questions. The appropriate group would be the dotnet.general which is where I've answered. Why did you think XML would be good place for this question?? -- Anthony Jones - MVP ASP/ASP.NET
0
7473
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...
0
7408
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...
0
7661
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. ...
0
5976
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...
1
5340
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...
0
4949
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
712
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...

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.