PDA

View Full Version : Enabling users to download csv


afranka
03-21-2003, 12:13 PM
Hi,

I am learning .net (C#) and am trying to create a way of allowing users to download a csv file based upon a dataset retrived from an SQL database using the user's search criteria.

I'll try to explain that a bit better!!!

A user goes to a telephone search page and selects users from a particular office. This list is retrieved from the SQL database and presented on screen.

I would like the user to be able to click on a download link and be able to save that particular data as a csv file to disk.

I know that .NET is server side, and I admittedly got myself comletely confused by learning to read and write text files (CSV etc.) using C# and thinking that I could use this principle to achieve the above. I am a bit confused about where the line is drawn between what you can and can't do between C# (.NET) and using C# on it's own.

Please can anyone point me in the right direction or explain what the deal is?

I'd be very grateful!

Thanks,
al.

arnyinc
03-21-2003, 01:40 PM
I have a similar situation. I use FSO to create a new file and give it a csv extension. Then I provide a link to that filename.

You have at least a couple choices as far as implementation. You can use a different filename (based on the date and time for example) each time to make sure no one ever overwrites a file before someone else downloads it. Or you can use the same filename and just keep overwriting the same file every time someone creates a report.

This is ASP and VBScript, but I think it would be similar in .Net and C#.

<%
'open connection named oConn

Set RS=oConn.execute("Select * from contactlist")

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("blah.csv", False)

MyFile.WriteLine("name, phone number, address")
WHILE NOT RS.EOF
MyFile.WriteLine("&RS("contact_name")&", "&(RS("contact_phone")&", "&RS("contact_addy")&")
RS.MoveNext
WEND

MyFile.Close
%>

whammy
03-22-2003, 02:48 AM
Actually I have an application that does something similar, although it's currently using .txt files, .csv is just another file extension. (Basically comma-delimited .txt file with double-quote field delimiters).

If you want a copy of what I have so far (although very simple - which might be even better), I will be glad to share it with you. ;-)