Excel .CSV problem with save

S

S_K

Hi,

I have a problem when I try to save a .CSV file from an ASP.NET web
page and the client has Excel open already. The symptoms are:

1) The web page is currently displaying the Excel spreadsheet with the
accurate data.
2) The .CSV file is saved from the server to the local hard drive of
the client.
3) An Excel spreadsheet is already running on the client (version 2002
of excel).
4) After the file is saved on the local (client) hard drive we notice
that another spreadsheet has been opened in the currently running
excel application. The name of the newly created file is "Object.csv".
5) The currently running spreadsheet data displays its own data under
it's own name.
6) When the Excel application has been killed and the saved .csv file
is opened the spreadsheet displays the data of the previously open
spreadsheet. In other words, the web page .CSV data has been replaced
by the open spreadsheet data!
7) When we try to save the web page .CSV file without Excel running it
saves fine.

This is a weird one! Is there anyway to save the .CSV file without
having it try to open in the Excel spreadsheet?

Thanks so much for your help!

Steve
 
S

S_K

Show your code.

Sorry,

Thanks for your help.

Here is my code:

protected void SaveExcel(object sender, EventArgs e)
{
int iColumnCount;

FileStream fs = new FileStream("C:/ExcellFiles/
exl.csv",FileMode.Create, FileAccess.Write);

StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0,SeekOrigin.End);

// get the column count
iColumnCount = GridView1.Columns.Count;

// fill the header
WriteHeader(sw);

foreach (GridViewRow row in GridView1.Rows)
{
WriteThisLine(iColumnCount, row, sw);
}
sw.Flush();
fs.Close();

Response.Redirect("https://mudotnet/ExcellFiles/exl.csv", false);
}

I hope that helps.

Steve
 
G

Guest

Mmm...

There is a cleaner way to do this, instead of creating a file on the
server side, you could create the file in memory and send it as an stream to
the client using the Response object.

I have used this approach with Excel XMLSS files without any issue, about
how to do this using CSV:


http://www.keithrull.com/PermaLink,guid,dc306cb9-e9cd-47df-8d7e-c6ba0fad159e.aspx

(may be you will need to register to this site).


http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=1485

http://blogs.msdn.com/adamhems/archive/2006/04/11/573458.aspx

Good luck
Braulio



/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top