3

i use closedxml in asp.net project to generate file excel, and now i want to save my excel file to my local pc but it now work. [i already tried from my local browser and it saved to my server folder]. i really need your guide. thanks.

and here is my code :

        Dim wb As XLWorkbook = New XLWorkbook
        wb.Worksheets.Add(datatable01, "sheetdata")
        wb.SaveAs("d:\myfolder\filereport.xlsx")

it's saved in "d:\myfolder\filereport.xlsx" in server side. i need it to my local pc, and if it possible i can choose file folder to save my file in my local pc folder (as file save dialog).

Deddy H
  • 252
  • 2
  • 6
  • 19
  • 1
    To get the Excel file to the client without saving it on the server first see this answer: http://stackoverflow.com/a/22298678/2610249 – Raidri Apr 29 '14 at 11:36

1 Answers1

5

i already changed my code and it work, strPath using Server.MapPath also

            ' save ke server
            Dim wb As XLWorkbook = New XLWorkbook
            wb.Worksheets.Add(datatable01, "sheetdata")
            wb.SaveAs(strPath)

            ' save ke local folder
            Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
            response.ClearContent()
            response.Clear()
            response.ContentType = "text/plain"
            response.AddHeader("Content-Disposition", "attachment; filename=" & rptName & ".xlsx" + ";")
            response.TransmitFile(strPath)
            response.Flush()
            response.End()
Deddy H
  • 252
  • 2
  • 6
  • 19