Results 1 to 4 of 4

Thread: Automatically Saving Excel file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    114

    Smile Automatically Saving Excel file

    Hi,

    Is there any mechanism for saving an excel file automatically. The Code which i used for Generting Excel file is
    [CODE]
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.ClearContent()
    HttpContext.Current.Response.ClearHeaders()
    HttpContext.Current.Response.Charset = ""
    HttpContext.Current.Response.Buffer = True
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + lstrExcelFileName)
    HttpContext.Current.Response.Write(_strBuild)
    HttpContext.Current.Response.Flush()
    [CODE]

    _strBuild contains the information to be displayed in the excel

    The above code when i use it prompts user for open/save an excel file. Is the any mechanism for saving an excel file automatically

    Thanks in Advance

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Automatically Saving Excel file

    Web browsers do not have the ability to display the contents of the excel file directly in the browser, which means you would need to either offer it as a download like you currently are or display it in a GridView or some other table yourself on the web page.

    As for offering it for download, there's no way to force the file to download to their computer, but in Firefox you can have the end user(s) configure it to automatically accept excel file downloads to a specific folder, but then they might not be aware of when one gets downloaded, if they dont see the FF download window then they'd have to go look in that folder to see if a new one has been downloaded/updated.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Automatically Saving Excel file

    Personally i would be really pissed if something started to save files on it's own.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Automatically Saving Excel file

    Quote Originally Posted by sapator View Post
    Personally i would be really pissed if something started to save files on it's own.
    Agreed! Doing this, without the permission of the logged in user would be a security risk, and as such, is not allowed. Unless explicitly handled by the browser in the case of Firefox, however, you can't rely on this being available.

    The best option would be to present the user with the Open/Save dialog, and let them decide what they want to do.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width