Value Cannot Be Null error
I've written the following code:
Dim fn As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("data") & "\" & fn
Dim test = ResolveApplicationDataPath("combinedTest.xls")
If Not FileUpload1.PostedFile Is Nothing And FileUpload1.PostedFile.ContentLength > 0 Then
FileUpload1.PostedFile.SaveAs(SaveLocation)
Else
Response.Write("Please select a file to upload.")
Response.Write("The file has been uploaded.")
End If
Dim excelengine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelengine.Excel
Dim workbook As IWorkbook = application.Workbooks.Open(SaveLocation)
Dim sheet As IWorksheet = workbook.Worksheets(0)
Dim sheettable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames)
Me.GridView1.DataSource = sheettable
Me.GridView1.DataBind()
workbook.Close()
excelengine.ThrowNotSavedOnDestroy = False
excelengine.Dispose()
'Response.Write(location)
When I run it, I get:
Value cannot be null.
Parameter name: root
Line 65: Dim excelengine As ExcelEngine = New ExcelEngine()
Line 66: Dim application As IApplication = excelengine.Excel
Line 67: Dim workbook As IWorkbook = application.Workbooks.Open(SaveLocation)
Line 68: Dim sheet As IWorksheet = workbook.Worksheets(0)
Line 69: Dim sheettable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames)
The stack trace:
[ArgumentNullException: Value cannot be null.
Parameter name: root]
Syncfusion.CompoundFile.Native.Storage..ctor(IStorage root, String storageName) +133
Syncfusion.CompoundFile.Native.Storage..ctor(IStorage root) +35
Syncfusion.CompoundFile.Native.CompoundFile.Open(Stream stream) +276
Syncfusion.CompoundFile.Native.CompoundFile..ctor(String fileName, STGM options) +153
Syncfusion.XlsIO.Implementation.ApplicationImpl.CreateCompoundFile(String fileName, STGM storageOptions) +55
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String strFileName, ExcelParseOptions options, Boolean bReadOnly, String password, ExcelVersion version) +380
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String strFileName, ExcelParseOptions options, ExcelVersion version) +67
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String FileName, ExcelVersion version) +62
Syncfusion.XlsIO.Implementation.ApplicationImpl.CreateWorkbook(Object parent, String strTemplateFile, ExcelVersion version) +51
Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open(String filename, ExcelVersion version) +49
Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open(String filename) +58
_Default.Button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\rsteckly\My Documents\Visual Studio 2008\WebSites\WebSite6\Default.aspx.vb:67
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
I don't see what's wrong with this. I've tried testing to see what the samples for XLSIO produce for a path to a file. It's still fundamentally a string to a file. Why then would it throw a null exception?
Dim fn As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("data") & "\" & fn
Dim test = ResolveApplicationDataPath("combinedTest.xls")
If Not FileUpload1.PostedFile Is Nothing And FileUpload1.PostedFile.ContentLength > 0 Then
FileUpload1.PostedFile.SaveAs(SaveLocation)
Else
Response.Write("Please select a file to upload.")
Response.Write("The file has been uploaded.")
End If
Dim excelengine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelengine.Excel
Dim workbook As IWorkbook = application.Workbooks.Open(SaveLocation)
Dim sheet As IWorksheet = workbook.Worksheets(0)
Dim sheettable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames)
Me.GridView1.DataSource = sheettable
Me.GridView1.DataBind()
workbook.Close()
excelengine.ThrowNotSavedOnDestroy = False
excelengine.Dispose()
'Response.Write(location)
When I run it, I get:
Value cannot be null.
Parameter name: root
Line 65: Dim excelengine As ExcelEngine = New ExcelEngine()
Line 66: Dim application As IApplication = excelengine.Excel
Line 67: Dim workbook As IWorkbook = application.Workbooks.Open(SaveLocation)
Line 68: Dim sheet As IWorksheet = workbook.Worksheets(0)
Line 69: Dim sheettable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames)
The stack trace:
[ArgumentNullException: Value cannot be null.
Parameter name: root]
Syncfusion.CompoundFile.Native.Storage..ctor(IStorage root, String storageName) +133
Syncfusion.CompoundFile.Native.Storage..ctor(IStorage root) +35
Syncfusion.CompoundFile.Native.CompoundFile.Open(Stream stream) +276
Syncfusion.CompoundFile.Native.CompoundFile..ctor(String fileName, STGM options) +153
Syncfusion.XlsIO.Implementation.ApplicationImpl.CreateCompoundFile(String fileName, STGM storageOptions) +55
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String strFileName, ExcelParseOptions options, Boolean bReadOnly, String password, ExcelVersion version) +380
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String strFileName, ExcelParseOptions options, ExcelVersion version) +67
Syncfusion.XlsIO.Implementation.WorkbookImpl..ctor(IApplication application, Object parent, String FileName, ExcelVersion version) +62
Syncfusion.XlsIO.Implementation.ApplicationImpl.CreateWorkbook(Object parent, String strTemplateFile, ExcelVersion version) +51
Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open(String filename, ExcelVersion version) +49
Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open(String filename) +58
_Default.Button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\rsteckly\My Documents\Visual Studio 2008\WebSites\WebSite6\Default.aspx.vb:67
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
I don't see what's wrong with this. I've tried testing to see what the samples for XLSIO produce for a path to a file. It's still fundamentally a string to a file. Why then would it throw a null exception?
SIGN IN To post a reply.
3 Replies
GM
Geetha M
Syncfusion Team
October 10, 2008 09:36 AM UTC
Hi Ron,
Thank you for your interest in Syncfusion products.
I was not able to reproduce the issue. I have created a sample using your code snippets and it is working fine for me. You can check it in the following link:
http://websamples.syncfusion.com/samples/XlsIO.Web/6.3.1.8/I50411/main.htm
Could you please try running the sample from the above link? If you still face issue, please send us your file so that it would help us to find the cause of the problem.
Please let me know if you have any concerns.
Regards,
Geetha
Thank you for your interest in Syncfusion products.
I was not able to reproduce the issue. I have created a sample using your code snippets and it is working fine for me. You can check it in the following link:
http://websamples.syncfusion.com/samples/XlsIO.Web/6.3.1.8/I50411/main.htm
Could you please try running the sample from the above link? If you still face issue, please send us your file so that it would help us to find the cause of the problem.
Please let me know if you have any concerns.
Regards,
Geetha
YV
Yuri van Oers
December 3, 2008 09:23 AM UTC
Had the same problem.
Using
application.Workbooks.Open(SaveLocation, ExcelOpenType.Automatic) fixed the issue for me.
(Am using v6.402.0.15 and C#)
Using
application.Workbooks.Open(SaveLocation, ExcelOpenType.Automatic) fixed the issue for me.
(Am using v6.402.0.15 and C#)
SR
Sridhar
Syncfusion Team
August 30, 2012 06:20 AM UTC
Hi Yuri van Oers ,
We are sorry for the delay in getting back to you.
Please let us know whehter the above reported is solved at your side and let us know if you require any further assitance on this.
Thanks,
Sridhar.S
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
AD Administrator
- Oct 9, 2008 08:07 PM UTC
- Aug 30, 2012 06:20 AM UTC