Excel .CSV problem with save

Discussion in 'ASP .Net' started by S_K, Nov 13, 2007.

  1. S_K

    S_K Guest

    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_K, Nov 13, 2007
    #1
    1. Advertising

  2. "S_K" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Nov 13, 2007
    #2
    1. Advertising

  3. S_K

    S_K Guest

    On Nov 13, 3:24 pm, "Mark Rae [MVP]" <> wrote:
    > "S_K" <> wrote in message
    >
    > news:...
    >
    > > 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
    S_K, Nov 14, 2007
    #3
  4. 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
    /// ------------------------------




    "S_K" wrote:

    > On Nov 13, 3:24 pm, "Mark Rae [MVP]" <> wrote:
    > > "S_K" <> wrote in message
    > >
    > > news:...
    > >
    > > > 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
    >
    >
    =?Utf-8?B?QnJhdWxpbyBEaWV6?=, Nov 14, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    648
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    713
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,703
    Andrew Thompson
    Feb 14, 2007
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,500
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. noydb
    Replies:
    3
    Views:
    1,393
    Tim Chase
    Jun 7, 2010
Loading...

Share This Page