473,583 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel .CSV problem with save

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
3 4457
"S_K" <st***********@ yahoo.comwrote in message
news:11******** *************@v 2g2000hsf.googl egroups.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
S_K
On Nov 13, 3:24 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"S_K" <steve_kers...@ yahoo.comwrote in message

news:11******** *************@v 2g2000hsf.googl egroups.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(objec t sender, EventArgs e)
{
int iColumnCount;

FileStream fs = new FileStream("C:/ExcellFiles/
exl.csv",FileMo de.Create, FileAccess.Writ e);

StreamWriter sw = new StreamWriter(fs );
sw.BaseStream.S eek(0,SeekOrigi n.End);

// get the column count
iColumnCount = GridView1.Colum ns.Count;

// fill the header
WriteHeader(sw) ;

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

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

I hope that helps.

Steve

Nov 14 '07 #3
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...@markNOSPA Mrae.netwrote:
"S_K" <steve_kers...@ yahoo.comwrote in message

news:11******** *************@v 2g2000hsf.googl egroups.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(objec t sender, EventArgs e)
{
int iColumnCount;

FileStream fs = new FileStream("C:/ExcellFiles/
exl.csv",FileMo de.Create, FileAccess.Writ e);

StreamWriter sw = new StreamWriter(fs );
sw.BaseStream.S eek(0,SeekOrigi n.End);

// get the column count
iColumnCount = GridView1.Colum ns.Count;

// fill the header
WriteHeader(sw) ;

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

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

I hope that helps.

Steve

Nov 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12368
by: Vikram | last post by:
Hi, Given below is my task. An user can open the xls file from my website (loaded on the top frame). After filling the Excel, he can click a send button at the bottom frame. By clicking the button i have to save the file in a shared directory on the web server by a unique name. Is it possible ?
2
5095
by: WZ | last post by:
I used the following code to create a workbook and save it in a webapplication. dim oExcel As Excel.ApplicationClass dim oBook As Excel.WorkbookClass dim obooks As Excel.Workbooks dim designb As Excel.Workbook dim osheets As Excel.Sheets dim result as string
2
1803
by: Bryan Harrington | last post by:
Hello all.. I'm working on some reports, and have added the ability to "download" the reports to excel. Not a big deal, fairly straight forward. However, PHB wants to be able to create some pivot tables from said reports (again.. no biggie) and when he goes to save the file, Excel wants to save the file as a web page instead of and Excel...
4
4515
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a tab delimited file or an excel file. The application then saves the file in the correct format. The flip side is for the user to import/upload the...
2
2470
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String = Session("User") & "-Customer List-" & Today() sFile = sFile.Replace("/", "") RbtnExport.Visible = False Select Case RbtnExport.SelectedItem.Value...
7
2419
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data (no database!)with some titles and info, is entered in the worksheet in a printable format. This is some of the code... Public exlAppl As...
6
2689
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save the excel document. When I click save I can save the excel document or when I click open it directly opens in excel. This works fine for all but one...
13
13197
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ABC.xls") HttpContext.Current.Response.Write(strHTML) HttpContext.Current.Response.End() However when the user tries to...
2
2796
by: iloveprincess | last post by:
Hi, I'm developing windows application using VB.Net 2005. I would like to send 'save' message using 'SendMessage' API to the excel appication. I've already got a handle of the excel window with 'FindWindow' API. How can I send 'save' command to external excel window? Actual thing I want to do is I can handle excel application in the...
3
7136
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this file but save it as an excel file. The data in this excel file will be imported into an Access database. The
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.