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

im trying to return a file from a request

Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file save
dialog

Anyone know how to do this?

TIA
Sam Martin
Nov 18 '05 #1
6 1342
text/plain is designed to show up in the browser. You can, potentially, save
the resulting csv instead of trying to stream it out. You then reidrect to
that file (popup window is easiest). NOTE, however, that the user may have
Excel set up to edit from the browser, so it picks up the CSV instead. AFAIK,
there is nothing you can do about the user's browser settings.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Sam Martin" wrote:
Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file save
dialog

Anyone know how to do this?

TIA
Sam Martin

Nov 18 '05 #2
One alternative is to put the CSV file into a Zip file. Zip files are always
prompted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:86**********************************@microsof t.com...
text/plain is designed to show up in the browser. You can, potentially, save the resulting csv instead of trying to stream it out. You then reidrect to
that file (popup window is easiest). NOTE, however, that the user may have
Excel set up to edit from the browser, so it picks up the CSV instead. AFAIK, there is nothing you can do about the user's browser settings.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Sam Martin" wrote:
Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file save dialog

Anyone know how to do this?

TIA
Sam Martin

Nov 18 '05 #3
Hi,

It is possible if you can stream it out ur input file. The below mentioned
code will help u out......

long fileSize=0;
fileStream = new FileStream("your_CSV_InputFileName.csv", FileMode.Open);
fileSize = fileStream.Length;
byte[] buffer = new byte[(int)fileSize];
fileStream.Read(buffer, 0, (int)fileSize);
string strAttachment="attachment; filename=abc.CSV";
Response.Clear();
Response.AddHeader("Content-Disposition: ",strAttachment);
Response.ContentType = "text/plain";
Response.BinaryWrite(buffer);
fileStream.Close();

Regards,
Kamal T.

"Sam Martin" wrote:
Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file save
dialog

Anyone know how to do this?

TIA
Sam Martin

Nov 18 '05 #4
Hello Sam,

Try adding this header to your response:
"Content-Disposition: attachment"

using
Response.AppendHeader("Content-Disposition", "attachment;filename=xxxxxx.csv")

-----
Ariel Popovsky

Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file
save dialog

Anyone know how to do this?

TIA
Sam Martin


Nov 18 '05 #5
thanks all,

all sorted now. (worked perfectly)

much appreciated

sam

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:e$**************@TK2MSFTNGP12.phx.gbl...
Hi all,

One of my pages needs to return a CSV file.

I've set the Response.ContentType = "text/plain"; but I don't want the
browser displaying the file, instead I want the user to get the file save
dialog

Anyone know how to do this?

TIA
Sam Martin

Nov 18 '05 #6
more specifically, if anyone else tries to do this.....

string fileName =
Convert.ToString("csvdump_"+System.DateTime.Now.To ShortDateString()+".csv").Replace("/","");;

byte[] buffer = System.Text.Encoding.ASCII.GetBytes(
<GET_MY_CSV_STRING()> );

string strAttachment="attachment; filename="+fileName;
Response.Clear();
Response.AddHeader("Content-Disposition: ",strAttachment);
Response.ContentType = "text/plain";
Response.BinaryWrite(buffer);

Response.End();
Nov 18 '05 #7

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

Similar topics

6
by: Alan Silver | last post by:
Hello, I have an ASP that takes a connection string and SQL statement in the querystring and is supposed to return the XML representation of the recordset to the Response stream (don't worry,...
3
by: John | last post by:
Greetings, I am running XP Professional. I have an exe file written in VC++. When I try to run it it flashes a command window at me and shuts down. I created a shortcut for it so I could set...
5
by: tshad | last post by:
I am trying to access my log files and am running into a permissions problem. I am doing the following: ****************************************************************** private void...
4
by: Lloyd Dupont | last post by:
I created a ============== public class LangModule : IHttpModule { public void Dispose() {} public void Init(HttpApplication application) { HttpContext context = application.Context;...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
by: Rahul | last post by:
I have Written a sample WCF service which shows Metadata info but when I call it I am getting the following error .. Server Error in '/WCF Client' Application....
3
by: Fantus | last post by:
Hello I am doing a small research and I found this: http://www.freedom-to-tinker.com/tinyp2p.html I tried to get it to work. So far I managed to run it as a server using a command:
3
li0pxh0
by: li0pxh0 | last post by:
Does anyone know how to fix this error? ERROR error.badfetch: Trying to add audio content <prompt> to non-audio container <form> Below is my code: use CGI; use Cwd; use File::Basename;...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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
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,...

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.