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

File Transfer To Client

Hi,

I have the following situation which I assume is a common one.
The user clicks a button to request a report. The report I produce is
a simple .csv text file. I want the report file to be transferred to
the client's machine presumably by bringing up the standard download
dialog for whichever browser they're using. What is the best way to
accomplish this using C# and .NET 2.0?

Thanks in advance.

Nov 14 '07 #1
8 7398
CMM
Look at Response.BinaryWrite(...).
Also, you might want to use Response.Append("Content-Disposition",
"attachment;filename=xxxx.xxx" ....) to add the filename.

<Da***********@gmail.comwrote in message
news:11*********************@v3g2000hsg.googlegrou ps.com...
Hi,

I have the following situation which I assume is a common one.
The user clicks a button to request a report. The report I produce is
a simple .csv text file. I want the report file to be transferred to
the client's machine presumably by bringing up the standard download
dialog for whichever browser they're using. What is the best way to
accomplish this using C# and .NET 2.0?

Thanks in advance.
Nov 14 '07 #2
Here is a snippet I use to transmit an Excel file to the client:

Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", @"attachment; filename="
+ Path.GetFileName(filePath));
Response.TransmitFile(filePath);

Hope this helps.

Colby
http://colbyafrica.blogspot.com

Nov 14 '07 #3
On Nov 14, 11:45 am, Colby Africa <colby.afr...@gmail.comwrote:
Here is a snippet I use to transmit an Excel file to the client:

Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", @"attachment; filename="
+ Path.GetFileName(filePath));
Response.TransmitFile(filePath);

Hope this helps.

Colbyhttp://colbyafrica.blogspot.com
Thank you very much! Using your code as a starting point I did a
little searching and came up with the following:

//---Send the file to the client
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", @"attachment;
filename=" +
Path.GetFileName(reportFilename));
Response.TransmitFile(reportFilename);
Response.End();

I am very grateful that there are selfless, generous people like you
in the world. Thanks again for the help.

Dave Couture

Nov 14 '07 #4
On Nov 14, 12:51 pm, DavidJCout...@gmail.com wrote:
On Nov 14, 11:45 am, Colby Africa <colby.afr...@gmail.comwrote:
Here is a snippet I use to transmit an Excel file to the client:
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", @"attachment; filename="
+ Path.GetFileName(filePath));
Response.TransmitFile(filePath);
Hope this helps.
Colbyhttp://colbyafrica.blogspot.com

Thank you very much! Using your code as a starting point I did a
little searching and came up with the following:

//---Send the file to the client
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", @"attachment;
filename=" +
Path.GetFileName(reportFilename));
Response.TransmitFile(reportFilename);
Response.End();

I am very grateful that there are selfless, generous people like you
in the world. Thanks again for the help.

Dave Couture
My pleasure!
Nov 14 '07 #5
CMM
I've also taken to keeping a somewhat exhaustive dos.extension-to-mime.type
table that I populate a dictionary with... so that I can dynamically set
Response.ContentType without knowing the filetype beforehand. You can find
some of these tables by doing google search. Here's an example:
http://silk.nih.gov/public/zzyzzap.@www.silk.types.html. Windows has these
tucked away somewhere too.... but I never quite figured out how to access
it.

"Colby Africa" <co**********@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
Here is a snippet I use to transmit an Excel file to the client:

Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", @"attachment; filename="
+ Path.GetFileName(filePath));
Response.TransmitFile(filePath);

Hope this helps.

Colby
http://colbyafrica.blogspot.com
Nov 15 '07 #6
Hey there. MIME data is stored in the registry. Check the key:

HKEY_CLASSES_ROOT\MIME\Database\Content Type

Colby

Nov 15 '07 #7
CMM
I don't remember what the problem was with this other than the roundabout
nature of working with it (first you need to lookup the dos .xxx extension
in HKCR... which may or may not exist). I'm also not sure if an ASP.NET has
access to these keys. Probably. Anyway, maintaining your own table (I keep
mine in a comma delimited text file that I read at app startup) is fairly
painless. :)

"Colby Africa" <co**********@gmail.comwrote in message
news:60**********************************@w73g2000 hsf.googlegroups.com...
Hey there. MIME data is stored in the registry. Check the key:

HKEY_CLASSES_ROOT\MIME\Database\Content Type

Colby
Nov 15 '07 #8
Nice!

Nov 15 '07 #9

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

Similar topics

8
by: Philipp Brune | last post by:
Hi all, the following problem occured to me and I hope somebody can help me : I need to implement an encrypted File download with a PHP script on the server side and a c# client application....
1
by: Neel Word | last post by:
I need to develop an application (development platform: Win2000; target platform: Win98/ME/NT4/2000/XP), which would require file transfer functionality over dial-up and network. We could...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
4
by: Jay | last post by:
Hi, I have some unique situations where i need to transfer a file from Server to client but without any Open or Save dialog box shown to the user. The file should save itself directly to client...
3
by: Jay | last post by:
Hi, I have some unique situations where i need to transfer a file from Server to client but without any Open or Save dialog box shown to the user. The file should save itself directly to client...
2
by: Jay | last post by:
Hi, I have some unique situations where i need to transfer a file from Server to client but without any Open or Save dialog box shown to the user. The file should save itself directly to client...
2
by: Bonzol | last post by:
vb.net 2003 Windows application We have a Client/Server system set up by communicating through a TCPClient object. The server loops continuously using a tcplistener device and each time a client...
4
by: pradqdo | last post by:
Hi folks, I have a very strange problem when I try to port my client/server program to cygwin. It is a simple shell program where the server executes client's commands + it can send and receive...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
5
by: raghubr | last post by:
Hi all, Can any one pls guide me through..I need to transfer the file from server to client and client to server using sockets in an Asynchronous mode so this file transfer doesn't hinder the...
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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.