This project has moved. For the latest updates, please go here.

Invalid character

Feb 4, 2013 at 2:46 PM
When i try to save file from dataset:
DataSet exportData = new DataSet();
...
 using (XLWorkbook xlWb = new XLWorkbook(XLEventTracking.Disabled))
{
         xlWb.Worksheets.Add(exportData.Tables[0]);
         xlWb.SaveAs(filePath.ToString() + fileName.ToString());
         result = true;
}
The file is saved but I get the following error:
"System.ArgumentException: '', hexadecimal value 0x04, is an invalid character."

The file is also locked, I can't open it or delete it. Why?

How can I solve this issue?

br,Simon
Coordinator
Feb 4, 2013 at 3:00 PM
My guess is that the table has a field with an end of transmission character which is messing up the file. I don't know why the file is locked, some process is using it?
Feb 4, 2013 at 3:41 PM
Yes, there is something like that.
But how can I solve this problem with this kind of characters?

SQL managment studio shows this character on screen and also If i copy character manually from table to excel file, I get square sign instead of character, not error.
Is it possible to save to excel file without error? Is there some property of closedXML, like ignore invalid characters or something similar.

Obviously , when error happens inside CLR, SQL holds lock to this file. I can't find the way to release lock from my code.

br, Simon
Aug 31, 2014 at 10:57 PM
I have the same error: '.', hexadecimal value 0x00, is an invalid character. My code has been working very good and sudenly these error, how do I fix it? Sorry, my english is not good enough.
Coordinator
Sep 1, 2014 at 1:55 AM
That's an illegal character in XML. You'll have to remove it somehow.

http://stackoverflow.com/questions/11036799/hexadecimal-value-0x00-is-a-invalid-character
Sep 1, 2014 at 5:06 AM
Thanks a lot MDeLeon, that link help me to fix the code.