473,382 Members | 1,359 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,382 software developers and data experts.

Sending a file to Response

I have an application in which I want to allow users to view certain files
that are on the server, but not part of the application. To do this, I
figured I would have ASP.NET read the files and send them to Response. I
have done this with images by reading them into a Bitmap object and then
using the following code:

Response.ClearContent()
Response.ContentType = "image/gif"
mybitmap.Save(Response.OutputStream, ImageFormat.Gif)

I will obviously need to use the Response.ClearContent() and
Response.ContentType lines, but because the files are not necessarily
images, I need to know how to send them to Response. I would have though
that

Response.WriteFile(filepath)
OR
Response.TransmitFile(filepath)

would work, but apparently they didn't. The basic idea is just reading and
writing a file, except the "writing" is more of a sending than a writing. I
know how to allow people to download a file (using the "content-disposition"
header), but what I want to do here is basically use a file in my site, but
not put the file in my site directory. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 19 '07 #1
2 2004
Greetings,

As far as I know, Response.WriteFile() SHOULD work...

Can you be more specific on what kind of error are you getting?

PJ
http://pjondevelopment.50webs.com

On Sep 19, 6:24 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I have an application in which I want to allow users to view certain files
that are on the server, but not part of the application. To do this, I
figured I would have ASP.NET read the files and send them to Response. I
have done this with images by reading them into a Bitmap object and then
using the following code:

Response.ClearContent()
Response.ContentType = "image/gif"
mybitmap.Save(Response.OutputStream, ImageFormat.Gif)

I will obviously need to use the Response.ClearContent() and
Response.ContentType lines, but because the files are not necessarily
images, I need to know how to send them to Response. I would have though
that

Response.WriteFile(filepath)
OR
Response.TransmitFile(filepath)

would work, but apparently they didn't. The basic idea is just reading and
writing a file, except the "writing" is more of a sending than a writing. I
know how to allow people to download a file (using the "content-disposition"
header), but what I want to do here is basically use a file in my site, but
not put the file in my site directory. Any ideas? Thanks.
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

Sep 19 '07 #2

Are you doing WriteFile() without setting ContentType? ContentType is
still required, WriteFile doesn't do it for you.

If you are setting ContentType, then what exactly is happening? Are
you getting an error? Are you getting an unexpected response? If so,
what exactly? Use an HTTP monitor like Fiddler to see what's actually
being sent; does it look correct?

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Wed, 19 Sep 2007 17:24:05 -0400, "Nathan Sokalski"
<nj********@hotmail.comwrote:
>I have an application in which I want to allow users to view certain files
that are on the server, but not part of the application. To do this, I
figured I would have ASP.NET read the files and send them to Response. I
have done this with images by reading them into a Bitmap object and then
using the following code:

Response.ClearContent()
Response.ContentType = "image/gif"
mybitmap.Save(Response.OutputStream, ImageFormat.Gif)

I will obviously need to use the Response.ClearContent() and
Response.ContentType lines, but because the files are not necessarily
images, I need to know how to send them to Response. I would have though
that

Response.WriteFile(filepath)
OR
Response.TransmitFile(filepath)

would work, but apparently they didn't. The basic idea is just reading and
writing a file, except the "writing" is more of a sending than a writing. I
know how to allow people to download a file (using the "content-disposition"
header), but what I want to do here is basically use a file in my site, but
not put the file in my site directory. Any ideas? Thanks.
Sep 20 '07 #3

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

Similar topics

2
by: Frostillicus | last post by:
I'm trying to get an ASP to return a zip file to the remote browser from an Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying: Cannot open C:\Documents and...
5
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
0
by: PJ | last post by:
I have the following code snippet to send a file stored as an image data type from sql server: Protected Sub StreamFile(ByVal fileItem As MyFile) Dim offset As Integer Dim buffer As Integer =...
0
by: Buddy Ackerman | last post by:
I'm sending file to the client (see sample code below) but when I send a large file the user gets a document contains no data message. response.contenttype = "application/x-unknown" myheader =...
0
by: Buddy Ackerman | last post by:
I'm sending file to the client (see sample code below) but when I send a large file the user gets a document contains no data message. response.contenttype = "application/x-unknown" myheader =...
1
by: Lars Netzel | last post by:
I have an XLS file that I try to send to the webclient via ASP.NET. When sending I use this code... Response.ClearContent() Response.ClearHeaders() Response.ContentType =...
1
by: Dirk Goossens | last post by:
Hello! I'm sending E-mails to mailadresses in a table, using the code below. How can I send more than one attachment? Access can find the file to be send in this field: MY_EMAILATTACHMENT_FIELD...
4
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes...
2
by: Nathan Sokalski | last post by:
I have an application in which I want to allow users to view certain files that are on the server, but not part of the application. To do this, I figured I would have ASP.NET read the files and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.