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

dynamically return another file type

I am trying to create an ASPX page that, based on QueryString inputs,
returns another file, in this case a WMA file. I do not want to do this by
redirect, because these files are not available publicly via the web, or via
a share. So i am returning it by opening a stream, and writing the bytes out
via Response.BinaryWrite().
This is all fine and dandy, but the Save As.. dialog lists the filetype as
ASPX page, and gives the page name...
how do i get it to list something else, and with the filetype being WMA (or
whatever i want)?
Is this even possible?

TIA,

Tim
Nov 18 '05 #1
5 1709
Here is an example of how to download or open a word document in you browser
using a FileStream.
In your case try using "video/x-ms-wma" as the ContentType.

Dim fs As New FileStream("c:\docs\0000001F.DOC", FileMode.OpenOrCreate,
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
Response.Buffer = True
Response.Clear()
Response.ContentType = "application/msword"

'Opens outside of the browser
'Response.AddHeader("content-disposition", "attachment;
filename=0000001F.DOC")
'Opens inside of the browser
Response.AddHeader("content-disposition", "inline; filename=0000001F.DOC")

Response.BinaryWrite(MyData)
Response.End()

Shawn
"Tim Mulholland" <Mu***************@alumni.virginia.edu> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
I am trying to create an ASPX page that, based on QueryString inputs,
returns another file, in this case a WMA file. I do not want to do this by
redirect, because these files are not available publicly via the web, or via
a share. So i am returning it by opening a stream, and writing the bytes out
via Response.BinaryWrite().
This is all fine and dandy, but the Save As.. dialog lists the filetype as
ASPX page, and gives the page name...
how do i get it to list something else, and with the filetype being WMA (or
whatever i want)?
Is this even possible?

TIA,

Tim

Nov 18 '05 #2
Attempted to try your example code this morning, but it seems i'm having
troubles getting into my development server... this code makes sense though,
so thanks for your help.
If i have any more questions once i get into my server, i'll post again, but
i'd guess this works.
Thanks again,

Tim

"Shawn" <bo********@hotmail.com> wrote in message
news:3f********@news.wineasy.se...
Here is an example of how to download or open a word document in you browser using a FileStream.
In your case try using "video/x-ms-wma" as the ContentType.

Dim fs As New FileStream("c:\docs\0000001F.DOC", FileMode.OpenOrCreate,
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
Response.Buffer = True
Response.Clear()
Response.ContentType = "application/msword"

'Opens outside of the browser
'Response.AddHeader("content-disposition", "attachment;
filename=0000001F.DOC")
'Opens inside of the browser
Response.AddHeader("content-disposition", "inline; filename=0000001F.DOC")

Response.BinaryWrite(MyData)
Response.End()

Shawn
"Tim Mulholland" <Mu***************@alumni.virginia.edu> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
I am trying to create an ASPX page that, based on QueryString inputs,
returns another file, in this case a WMA file. I do not want to do this by
redirect, because these files are not available publicly via the web, or via a share. So i am returning it by opening a stream, and writing the bytes out via Response.BinaryWrite().
This is all fine and dandy, but the Save As.. dialog lists the filetype as
ASPX page, and gives the page name...
how do i get it to list something else, and with the filetype being WMA (or whatever i want)?
Is this even possible?

TIA,

Tim

Nov 18 '05 #3
Hi Tim,

Thanks for posting in the group.

I agree with Shawn. ContentType should do the trick for you. It could tell
client browser how to deal with the data stream in the http response.

If you have any more concerns on it, please feel free to post in the group.

Best regards,
Yanhong Huang
Microsoft Community 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
I finally was able to test my code.
I was using ContentType, but it was the AppendHeader, content-disposition
stuff that got me going in the right direction.
Seems to work beautifully.
Thanks to all,

Tim

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> wrote in message
news:4L**************@cpmsftngxa07.phx.gbl...
Hi Tim,

Thanks for posting in the group.

I agree with Shawn. ContentType should do the trick for you. It could tell
client browser how to deal with the data stream in the http response.

If you have any more concerns on it, please feel free to post in the group.
Best regards,
Yanhong Huang
Microsoft Community Support

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

Nov 18 '05 #5
Hi Tim,

Ahh, Then I should say thanks to Shawn again. :) I haven't noticed that
contect-disposition is so important under this situation. Thanks very much
for your response.

I just did a quick search in MSDN and found this info:

-----------
Content-disposition is an extension to the MIME protocol that instructs a
MIME user agent on how it should display an attached file. The range of
valid values for content-disposition are discussed in Request for Comment
(RFC) 1806 (see the "References" section of this article). This article
focuses on the "attachment" argument, which instructs a user agent (in this
case, Internet Explorer) to save a file to disk instead of saving it inline.

When Internet Explorer receives the header, it raises a File Download
dialog box whose file name box is automatically populated with the file
name that is specified in the header. (Note that this is by design; there
is no way to use this feature to save a document to the user's computer
without prompting him or her for a save location.)

There are two ways that you can use Internet Explorer to specify a
content-disposition header for a file: dynamically and statically.

To apply the header dynamically, create an Active Server Pages (ASP) file
that writes the document out to the browser. Use the Response.AddHeader
method to add the content-disposition header. For example:
Response.AddHeader "content-disposition","attachment; filename=fname.ext"

Instructions on how to perform a binary write for nontext documents are
available in the following Microsoft Knowledge Base article:
193998 HOWTO: Read and Display Binary Data in ASP

This technique is ideal when you want to protect a document store on your
server, especially one that exists outside of the Web root.

To apply the header statically, right-click the document in the Internet
Service Manager, and then select Properties. Select the HTTP Headers tab
and enter the content-disposition header there. This works best when you
only want to apply content-disposition to a few files on your system and
don't require the overhead of ASP.

Please note that this solution will not work in Internet Explorer 4.01 due
to a bug. For additional information, click the article number below to
view the article in the Microsoft Knowledge Base:
182315 FIX: Content-Disposition: Does Not Force File Download Dialog
-----------

RFC 1806, RFC 2183 describe more on it.

Anyway, I am glad that the problem is resolved. If you have any more
questions, pleaes feel free to post in the group.

Thanks again for participating the community.

Best regards,
Yanhong Huang
Microsoft Community 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

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

Similar topics

7
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2...
7
by: cjl | last post by:
Hey all: I've searched the newsgroup, and googled, but I'm stuck. I want to be able to 'dynamically' add a .js file to a web page after the page has loaded, based on user interaction. For...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
7
by: Serpent | last post by:
The C-FAQ describes some techniques here: http://c-faq.com/aryptr/dynmuldimary.html I was using something slightly different from the C-FAQ and I was wondering if it was legal. Say I want a...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.