By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

Excel .CSV problem with save

P: n/a
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

Nov 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"S_K" <st***********@yahoo.comwrote in message
news:11*********************@v2g2000hsf.googlegrou ps.com...
This is a weird one! Is there anyway to save the .CSV file without
having it try to open in the Excel spreadsheet?
Show your code.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 13 '07 #2

P: n/a
S_K
On Nov 13, 3:24 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"S_K" <steve_kers...@yahoo.comwrote in message

news:11*********************@v2g2000hsf.googlegrou ps.com...
This is a weird one! Is there anyway to save the .CSV file without
having it try to open in the Excel spreadsheet?

Show your code.

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
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

Nov 14 '07 #3

P: n/a
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,g...a0fad159e.aspx

(may be you will need to register to this site).
http://discuss.fogcreek.com/dotnetqu...ow&ixPost=1485

http://blogs.msdn.com/adamhems/archi...11/573458.aspx

Good luck
Braulio

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


"S_K" wrote:
On Nov 13, 3:24 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"S_K" <steve_kers...@yahoo.comwrote in message

news:11*********************@v2g2000hsf.googlegrou ps.com...
This is a weird one! Is there anyway to save the .CSV file without
having it try to open in the Excel spreadsheet?
Show your code.

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net

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

Nov 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.