C# export file to download
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 6 months ago. Active 5 months ago. Viewed k times. I have a large ish form in MVC. I need to be able to generate an excel file containing data from a subset of that form. Community Bot 1 1 1 silver badge. Valuk Valuk 1, 3 3 gold badges 15 15 silver badges 21 21 bronze badges.
Add a comment. Active Oldest Votes. UPDATE September My original answer below was over 3 years old, so I thought I would update as I no longer create files on the server when downloading files via AJAX however, I have left the original answer as it may be of some use still depending on your specific requirements. SaveAs memoryStream ; memoryStream.
The window. Combine Server. This looks like a good potential option, but before I go ahead with it, are there no other alternatives that don't involve creating the file on the server first? Not that I am aware of - this approach I have used successfully many times. From the users perspective it is seamless, the only thing to be mindful of is that you will need a housekeeping routine to tidy up the files that are created as they will mount up over time.
Great, why don't you put the old answer at the bottom? And the new answer at the top, so people don't waste time — goamn. Show 13 more comments. AGuyCalledGerald 7, 16 16 gold badges 67 67 silver badges bronze badges.
Luchian Luchian 2 2 silver badges 3 3 bronze badges. How exactly would you do that? Sounds interesting. An example would be nice i mean how to store it in the cache, not generating the excel file.
How scalable is this though? If a user is downloading several large reports? SaveXlsx stream ; stream. Andy S Andy S 1 1 silver badge 2 2 bronze badges. I had a similar approach.
WriteDataTableToExcel dt, ". IntValue ' Read from Ranges of cells elegantly. Max Function c c. Copy code to clipboard VB C. Download DLL Manually install into your project.
Install-Package IronXL. CreateWorkSheet "Countries". Value; result. Value result. DateErrorMessage Next i workbook. ExecuteNonQuery ; optionsBuilder. UseSqlite connection ; base. CreateCommand 'Create the database if it doesn't already exist command. ExecuteNonQuery optionsBuilder. UseSqlite connection MyBase. Value ,. First 'Set the formula for the Percentage of Total column cell. NET on GitHub. View the API Reference. Christian Findlay Software Development Team Lead Christian builds software for the health industry and leads up a team.
Previous Tutorial. Next Tutorial. Human Support Talk directly with our development team Ask a Question. Documentation Clear online manuals in plain English. Then a loop is executed over the Columns and Rows of the DataTable and a comma separated delimited string is generated. Finally comma separated delimited string is written to the Response which initiates the File download.
ConnectionStrings[ "constr" ]. Fill dt ;. Clear ;. Write csv ;. Flush ;. End ;. ConnectionStrings "constr". Using con As New SqlConnection constr. Using dt As New DataTable. Fill dt. Write csv. Workbook xlsWorkbook; Excel. SetAttributes oldFile. FullName, FileAttributes. Normal ; oldFile. Message, "Error", MessageBoxButtons.
OK, MessageBoxIcon. Worksheet xlsWorkbook. Get data from pubs database, table authors"; Excel. Merge 1 ; range. ToArgb ; range.
0コメント