CSV to save on server, (not user's PC)


I have been using the following article to make a CSV file of a dataset.
C:\Documents and Settings\Glyn Aston\Desktop\CSV\New Folder (2)\DotNetBips_com  The _NET Knowledge Base.htm
The CSV file is created on a button click and then the user gets a popup to choose a location to save the file.

I want to modify this code to save the file in a set location on the web server.

How do I do this??


2/21/2006 6:43:45 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 38

You gave us a link to a file on your Hard Drive.

I'm assuming your talking about this article


At the end of the article, they are using these lines



These are the methods that send the file to the user, look into the System.Text namespace, and use the TextWriter class to write the data (it's currently in byte format, your going to have to convert it) to a specified place on the Servers Hard Drive.

Bryan Sampica
Auction Site StarterKit |
My Blog
2/21/2006 7:55:54 PM

Thanks for the fast response...

Can you please expand on your answer.
I have declared the system.text namespace, but TextWriter isn't recognised.
When you say I need to convert it, do you mean by using the XmlTextWriter??

If so the only example I could find was on MSDN.

Is this what you meant?

If so/not, can you refer me to some good articles.



2/21/2006 9:34:12 PM

Here's a short workup of how to write a byte to a text file.

Imports System.Text

Imports System.IO

Dim B() As Byte = {255, 255, 124, 220}

File.WriteAllBytes("c:\test.txt", B)

In your case, your going to want to NOT dim the B() variable, you'll want to use your array of bytes that was captured in your example, so it'd be more like this...

File.WriteAllBytes("c:\text.txt" , data)


Bryan Sampica
Auction Site StarterKit |
My Blog
2/22/2006 1:39:10 PM


I was a little confused when I cut and pasted the code and I got an error saying:

    'WriteAllBytes is not a member of System.IO.File'

A quick google search, and I relise that this is a .Net 2 instruction.

I eventually got this to work by downloading Visual Web Developer Express. My project has been developed in VS2003 and I'm reluctant to change before completing this project.

Is it possible to get asp.net2 stuff to work under VS2003? (I've tried changing it in IIS with no luck)

If not how was this done in asp.net 1.1?


2/23/2006 8:22:43 PM
It's not really possible.  It's how your codebehind is compiled into IL, and read by the framework.  If your developing in a 1.1 enviroment, it has to run under the 1.1 framework.
Bryan Sampica
Auction Site StarterKit |
My Blog
2/23/2006 10:22:35 PM

I don't know what the "proper technique" is but here is what I do:

imports system.web.hosting

Dim strFileName, strTheStuffToSave as String

strTheStufftoSave = 'create a string of your data here

strFileName =  HostingEnvironment.ApplicationPhysicalPath _

& "App_Data\yourcsvfile.csv"


It took me a while to figure out that it was the hosting environment I needed to use to get it to save to the server instead of the desktop. Obvioulsy your directory may differ from App_Data.

Hope this helps,



2/24/2006 5:27:33 AM

Thanks but HostingEnvironment must also be a .Net2 feature as VS2003 will not recognise it.

Does anyone know how I can save this file to the server under .net 1.1


3/6/2006 1:00:17 PM

string outputFilename = "someFile.txt";
string textOutput = "some text to write";

outputFilename = System.Web.HttpContext.Current.Server.MapPath(outputFilename);

System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(outputFilename, true);



Remember that the ASPNET machine account has to have permissions to write/create this file.



3/6/2006 1:29:04 PM

Similar Artilces:

Mozilla get's no style tag's from .net server.
I made a webform in web matrix, and it looks fine in IE. If I open the same link whit Mozilla, it looks like a disaster. When I look at the HTML source, there are no style tags as in IE. But when I save the HTML source from IE (the one whit style tags) and open it in Mozilla, it looks perfect. So the onley reason the webform looks wrong in Mozilla, is because the .net server detects Mozilla and not IE and sends a style less HTML source. Wy? Mozilla does support style tags. Is there a solution for this bug? Or is this a uh.. feature? ..Mivz Update, I have got some more info. It is ...

Saving a file from the server on to user's PC.
I have a subprocedure where upon clicking on the link button on a webpage,the subprocedure will save data from a datagrid,write it to a text file and save it on to the user's PC.Does anyone know how do i go about doing this? Change the content type of the page sending the text to this: application/octet-stream Then use Response.Write(ALLTEXT)Picky Hi. I want to do similar things, seting the same content type, but want to change the name of the saved file. For example, I have a page named "Download.aspx" which generates binary output and the user to be prompted to save ...

changes made from one user's webpart's page, effects all user's
 I am just doing this offline right now in Visual Web Developer Express 2008I created the login inonce in the memberpage area, people can modify their webpart page. I created several users to test this out.  I loaded it in a browser.When I make changes as logged in user "A" .  Then logout and login as user "B", user "B,s" webpart page has been changed to user "A".This goes true for whomever I log in as.  It changes for everyone.Is there something specific I need to do in order to get everyone's changes to be unique for them...

Getting error "Login failed for user ''. The user is not associated with a trusted SQL Server connection" on trying to authenticate a user
Hi, I created aspnetdb on Sql Server 2005 and modified my web.config LocalSqlServer connection string to connect to the Sql Server instead of mdf file on Sql Server. When i click Log In button on my login control i am getting the error "Login failed for user ''. The user is not associated with a trusted SQL Server connection" But when i bind a radio button list or any control to select from aspnet_users or roles table data is displayed fine without any login errors (i am using aspnetdbConnectionString given below for binding data). Why is it happening only when i authenticate but...

How can I get out of my Mozilla's browser the Winamp browser and get back the Google's or Mozilla's browser.
Please I have got to my browser ( I don't know how.) the Winamp browser he behave like virus stick in.But he doesn't has uninstalation section so I can't do anything to get him away from Mozilla's file. I'm not happy of Winamp's behave its like advertisement against a customer's will. Please is there any way to get him away from Mozilla?Please send me exact direction I have tried many ways but he is deeply inside the systeme so when I install new Mozilla he is always here ready to pester me. Thank you for an answer. Richard ...

[wxperl-users] Getting started: Finding ID's
(Hopefully HOWTO questions aren't frowned upon in this list - I'm fairly proficient in Perl and Perl/Tk, but not at all in wxwidgets. Plus, the C++ based wxwidgets docs are hard for me to follow. So as I go through the steps of porting my app, I'll probably be asking a lot of questions) I used wxGlade to build out a mockup of the GUI for my app, and save the resulting wxPerl code. I've got three windows - a main window and two sub-windows. I'm trying to hook the menu up so that selecting the proper option on the menubar in the main menu will pop up one of...

A Windows user's guide to getting started with Linux
A Windows user's guide to getting started with Linux http://www.newsforge.com/os/04/05/24/143250.shtml As Linux gains momentum, many longtime Windows users are beginning to take notice. With Linux's legendary stability, security, and low cost, the draw is obvious. But if you're a Windows user, how do you know where to begin? This article summarizes the easiest ways for Windows users to get started in Linux or to make a full migration. If you are thinking about making a switch but are worried about the hassle of installing a new operating system, you're not al...

In debug mode I get Login failed for user ''. The user is not associated with a trusted SQL Server connection.
The error msg only appears when I try and debug. When using the site normally there is no problem?? Hello,     The reference below is the solution of your problem.     The user is not associated with a trusted SQL Server connectionPlease give us feedback no matter whether you get your answer.Please "mark as answer" if it's useful for youSincerely,Jerome...

How to get remote pc's name when running on terminal server?
Hi all! I'm looking for a trick that would help me to identify the user who is using a terminal server session when connecting to the database. When the user is under the local network, I use the pc's network name and I was wondering if I could get that info under TS too. Any guidance is welcome. PB 10.2.1 WinXP/ Win2000 Server and Win2003 Server Sybase ASE 12.5 / 15.0 On Sep 23, 7:15=A0am, "Manuel Espinoza" <jmespinoza_no_spam@seicom_dot_com_dot_mx> wrote: > Hi all! > > I'm looking for a trick that would help me to identify the...

I built a contact page using System.Net.Mail that captures the user's email address from a text box in the UI. I'm using a validator for the format of the email but ... there's no way to insure the email address actually belongs to the user. Is there a way to get that from the user's environment or at least get the IP address of the sending machine?  Thanks! Pat That should get you their IP address.  Request.UserHostAddress   I would think you either need to develop some kind of ASP.NET membership schema or if you have user email data stored cent...

User's home directory saved in Samba server not locally
Hi guys, Continuing with my assigned task of migrating the company's PCs to GNU/Linux ('openSUSE as server for GNU/Linux clients' (http://tinyurl.com/5sqzjl7)) I managed to set up a DC with roaming profiles for the few remaining Windows users, user validation and login for the openSUSE boxes and a few network shares with different rights. I know there are no roaming profiles for GNU/Linux and I can live with that but I would like to specify wich users/groups would have their home directories saved locally (notebook users) and which will save them on the Samba server...

Modify my export csv code to save to the server instead of user' machine?
Hi all,I have this code that upon call, will export a GridView to csv file and ask the user where to save on the user' machine. Now I want to change it so that it will save to the server instead. What should I do? 1 public void ExportToCSV(GridView myGV, string fileName) 2 { 3 Response.Clear(); 4 Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.csv", fileName)); 5 Response.Charset = ""; 6 Response.ContentType = "application/vnd.csv"; 7 8 ...

Dropdownlist on website
When I access an application written in asp.net 2.0 on my pc (uses XP) and on a laptop (using Vista), I can type into the dropdownlist to search for a record.  But other pc's (using XP) do not allow the user type to do a search.  Only the first letter of the word or the drop down are available to do a search.   Does anyone know why it would work with some pc's but not on others? I think this behaviour is in IE 7, check to see what versions of IE the PC's have that done work.-------------------------------------------------------...

How to allow a user to save a dataset's table to a csv file on his/her computer?
I have a web form in which the view state contains a dataset. I want to allow the user to convert this dataset's table to a csv file  that gets saved on user's computer. Proibaby, the user on clicking the 'Export to CSV' button should get a file dialog to specify the location to save the file. Thanks.sun21170 in your button click event handler u need to do something like this StringBuilder output = new StringBuilder();DataSet ds = (DataSet)ViewState["name"];StringBuilder line= new StringBuilder();foreach(DataColumn c in ds.Tables[0].Columns){if(line.length > 0 ){  &...

Web resources about - CSV to save on server, (not user's PC) - asp.net.getting-started

Resources last updated: 12/5/2015 3:45:58 PM