rainbowShiningUnicorn rainbowShiningUnicorn - 29 days ago 9
C# Question

C# ASP.NET Retrieving file address in string

I am building a method that will build an XLS file and uploading it on user's computer.
I am using this guide:
http://csharp.net-informations.com/excel/csharp-create-excel.htm

So code that will define my destination address is:

xlWorkBook.SaveAs("C:\\Something\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal);


Now it is default, but i want to allow user to define it by him self, so as far as i understand, i need an html field, which will open common "browse window" and save file path to string, which will be later used in
xlWorkBook.SaveAs
function. I have read a bit about FileUpload, but i don't really sure that it is what i am looking for.

Tim Tim
Answer

The code that you have there will save the file on the web server itself, not on the user's computer. You'll need to stream the file down to the user via the browser, and then they will be able to choose where to save it.

You could save the file on the server and then stream it to the user using Response.WriteFile, or you could stream it from memory if you don't want to keep a copy of the file on the server.