We help IT Professionals succeed at work.

Question of Load xls to XmlDoc

chuang4630
chuang4630 asked
on
I try to load the .xls (NOT .xlsx) to XML but failed every time. This existing code has been in production for long time so I do not think it is the problem. The error message:

Invalid character in the given encoding. Line 1, position 1..

The source Uri:
file:///F:/Clientdata/ACC/Services/Transport/Ftp/In/Market/Decrypted/MassEnroll - 2011-03-22- ProvisionFood2.xls

Any idea what might go wrong? Sorry I cannot  upload the test file since there are many sensitive information.






Comment
Watch Question

Author

Commented:
The code:

                var xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

Most Valuable Expert 2011
Top Expert 2015

Commented:
An ".xls" file is not XML--it is a binary file that represents an Excel workbook. A ".xlsx" file is just the newer 2007+ format for Excel files. They are also binary files. In order to load the data into an XmlDocument class, you would need to save the file into XML format. For example, Excel 2003 provides you with this option:
Untitled.png

Author

Commented:
I save the file as XML. It causes error:

Workbook does not have XML Mapping.
Most Valuable Expert 2011
Top Expert 2015
Commented:
I think I highlighted the wrong option. Try using the "XML Spreadsheet" option.