0

I have a web site that is using ClosedXML to create Excel Files. When I publish it will not run. I am getting no error messages, but it seems not to run.

 Dim dt As New DataTable
    dt = Session("excelDataTable")
    Dim wb As New ClosedXML.Excel.XLWorkbook()
    Dim ds As New DataSet
    ds.Tables.Add(dt)

    Dim strFileNameGuid As String = Guid.NewGuid.ToString()
    Dim strFileLocation As String = MapPath("ExcelExports") & "\"

    wb.Worksheets.Add(ds)
    wb.SaveAs(strFileLocation & "ConstructionExport" & strFileNameGuid & ".xlsx")

    hyDownloadExport.Visible = True
    hyDownloadExport.NavigateUrl = "~/ExcelExports/ConstructionExport" & strFileNameGuid & ".xlsx"

The DLLS are in the bin folder. Thanks for any and all assistance!!!

CODE EDIT

 Try
        Dim dt As New DataTable
        dt = Session("excelDataTable")
        Dim wb As New ClosedXML.Excel.XLWorkbook()
        Dim ds As New DataSet
        ds.Tables.Add(dt)

        Dim strFileNameGuid As String = Guid.NewGuid.ToString()
        Dim strFileLocation As String = MapPath("~/ExcelExports")

        wb.Worksheets.Add(ds)
        'wb.SaveAs(strFileLocation & "\ConstructionExport" & strFileNameGuid & ".xlsx")
        wb.SaveAs(Path.Combine(strFileLocation, "ConstructionExport" & strFileNameGuid & ".xlsx"))
        hyDownloadExport.Visible = True
        hyDownloadExport.NavigateUrl = "~/ExcelExports/ConstructionExport" & strFileNameGuid & ".xlsx"
    Catch ex As Exception
        Weez.Utilities.log(System.DateTime.Now.ToString & ": construction.aspx > export exce; " & ex.Message, "ExceptionErrors")
    End Try
dindryte
  • 46
  • 8
  • 1
    Have you had a look on the server to see if the files are being created somewhere else? Using `MapPath("~/ExcelExports")` would be a good idea, as would the use of `Path.Combine` in `SaveAs` instead of manually adding the path separator. Oh, and make sure that the identity your website runs under has write access to the relevant directory. – Andrew Morton Oct 08 '16 at 18:37
  • Thanks for suggestion, unfortunately that did not help. – dindryte Oct 08 '16 at 19:18
  • Do you happen to have that in a Try..Catch structure which is hiding errors from you? Have you looked in the Windows event logs, just in case something useful is in there? – Andrew Morton Oct 08 '16 at 19:22
  • yes I have Try.. Catch however it does not seem to be catching anyting – dindryte Oct 08 '16 at 19:44
  • OK, comment out the Try..Catch and let it give you an error message, if there is one. – Andrew Morton Oct 08 '16 at 19:54
  • does not give an error. selects button and just does not build the file. thanks for your help! – dindryte Oct 08 '16 at 20:17
  • You're going to have to figure out some way of debugging the application on the server, maybe log each step and the values of variables. – Andrew Morton Oct 08 '16 at 20:20
  • Try saving the ClosedXML to a MemoryStream first and inspect the streams contents. If you see any contents, you can then save the MemoryStream's bytes to a file. In fact, if that works, I would suggest that you serve the contents of the MemoryStream directly to the client, instead of redirecting to a file. Unless you really really want to have a file on the disk. – Francois Botha Oct 10 '16 at 10:28

0 Answers0