473,401 Members | 2,146 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,401 software developers and data experts.

context.Response.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.ProcessRequest

' Set up the response settings

context.Response.ContentType = "image/jpeg"

context.Response.Cache.SetCacheability(HttpCacheab ility.Public)

context.Response.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Original

Select Case context.Request.QueryString("Size")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Medium

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Original

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

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

AndAlso (context.Request.QueryString("PhotoID") <"")) Then

id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))

stream = PhotoManager.GetPhoto(id, size)

Else

id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))

stream = PhotoManager.GetFirstPhoto(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.GetPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

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

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

context.Response.OutputStream.Write(buffer, 0, count)

count = stream.Read(buffer, 0, buffersize)
Loop

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

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

George.
"AAaron123" <aa*******@roadrunner.comwrote in message
news:eo**************@TK2MSFTNGP03.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.ProcessRequest

' Set up the response settings

context.Response.ContentType = "image/jpeg"

context.Response.Cache.SetCacheability(HttpCacheab ility.Public)

context.Response.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Original

Select Case context.Request.QueryString("Size")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Medium

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Original

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

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

AndAlso (context.Request.QueryString("PhotoID") <"")) Then

id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))

stream = PhotoManager.GetPhoto(id, size)

Else

id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))

stream = PhotoManager.GetFirstPhoto(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.GetPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

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

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

context.Response.OutputStream.Write(buffer, 0, count)

count = stream.Read(buffer, 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.Response.ContentType = "image/jpeg" line caused the
dialog box to open?

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

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

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*****@comcast.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Here you go
http://support.microsoft.com/kb/260519/EN-US/

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

George.
"AAaron123" <aa*******@roadrunner.comwrote in message
news:eo**************@TK2MSFTNGP03.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.ProcessRequest

' Set up the response settings

context.Response.ContentType = "image/jpeg"

context.Response.Cache.SetCacheability(HttpCachea bility.Public)

context.Response.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Original

Select Case context.Request.QueryString("Size")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Medium

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Original

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

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

AndAlso (context.Request.QueryString("PhotoID") <"")) Then

id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))

stream = PhotoManager.GetPhoto(id, size)

Else

id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))

stream = PhotoManager.GetFirstPhoto(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.GetPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

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

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

context.Response.OutputStream.Write(buffer, 0, count)

count = stream.Read(buffer, 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.AddHeader("content-disposition","attachment; 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.ProcessRequest

' Set up the response settings

context.Response.ContentType = "image/jpeg"

context.Response.Cache.SetCacheability(HttpCacheab ility.Public)

context.Response.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Original

Select Case context.Request.QueryString("Size")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Medium

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Original

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

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

AndAlso (context.Request.QueryString("PhotoID") <"")) Then

id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))

stream = PhotoManager.GetPhoto(id, size)

Else

id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))

stream = PhotoManager.GetFirstPhoto(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.GetPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

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

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

context.Response.OutputStream.Write(buffer, 0, count)

count = stream.Read(buffer, 0, buffersize)
Loop

End Sub
Nov 13 '08 #4

"bruce barker" <br*********@discussions.microsoft.comwrote in message
news:C0**********************************@microsof t.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.AddHeader("content-disposition","attachment;
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.ProcessRequest

' Set up the response settings

context.Response.ContentType = "image/jpeg"

context.Response.Cache.SetCacheability(HttpCachea bility.Public)

context.Response.BufferOutput = False

' Setup the Size Parameter

Dim size As PhotoSize = PhotoSize.Original

Select Case context.Request.QueryString("Size")

Case "S"

size = PhotoSize.Small

Case "M"

size = PhotoSize.Medium

Case "L"

size = PhotoSize.Large

Case Else

size = PhotoSize.Original

End Select

' Setup the PhotoID Parameter

Dim id As Int32 = 1

Dim stream As IO.Stream = Nothing

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

AndAlso (context.Request.QueryString("PhotoID") <"")) Then

id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))

stream = PhotoManager.GetPhoto(id, size)

Else

id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))

stream = PhotoManager.GetFirstPhoto(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.GetPhoto(size)

End If

' Write image stream to the response stream

Dim buffersize As Integer = (1024 * 16)

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

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

context.Response.OutputStream.Write(buffer, 0, count)

count = stream.Read(buffer, 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
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...
3
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...
7
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...
0
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...
0
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...
1
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...
12
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...
1
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...
0
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...
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
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,...
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
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...

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.