Link to home
Start Free TrialLog in
Avatar of LaserdogLezly
LaserdogLezly

asked on

Save csv File to Desktop

I have a .NET web app that queries a mySQL DB. I want to send the results to an Excel file/datatable on the users desktop.

Everything seems to work fine, but the file isn't there. But when I run the app a 2nd time, I get an error that the file exists, but there is no file.

Here's my file path & SQL query.

string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                                     "dataTable.csv"); 
                                     
string sql3 = "SELECT * FROM table_173 " +     
              " INTO OUTFILE '" + fileName + "' " +
              " FIELDS TERMINATED BY ',' " +
              " ENCLOSED BY '\"' " +
              " LINES TERMINATED BY '\n'; ";

Open in new window

             
             
The following SQL query works fine & the file is there.
             
string sql2 = "SELECT * FROM table_173 " + 
              " INTO OUTFILE 'C:/LH/dataTable.csv' " +
              " FIELDS TERMINATED BY ',' " +
              " ENCLOSED BY '\"' "  + 
              " LINES TERMINATED BY '\n'; ";

Open in new window

SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LaserdogLezly
LaserdogLezly

ASKER

I saved an HTML file to the desktop successfully. What's the difference?


string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                                     "feeschedule.html");

         System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
         file.WriteLine(myHtmlFile);     
         return myHtmlFile;

Open in new window



on edit: I just checked the remote server & there is no file there.
which desktop?
I saved an HTML file to my desktop.
is this the same machine that hosts the web site?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Both responses were correct in that I was saving to a remote server with permissions.