Hi
I have below code . I want if file has file extendsion .xml then first it should be saved as .xls with same name
string FolderPath = "~/Upload/ExcelUpload/";
string FilePath = Server.MapPath(FolderPath + RandomName + FileName);
FileUpload1.SaveAs(FilePath);
Thanks
Leon DPosted Apr 21, 2023, 8:31 AM
You can read the XML file into a datatable, then use Spire.XLS to convert the datatable to an XLS file.
https://www.nuget.org/packages/Spire.XLS/
Ramco RamcoPosted Apr 13, 2023, 8:41 AM
Hi Naimish
I have uploaded file . In Datatable it shows 4 fields Author , Last Author Created , Version.
/forums/uploadfile/f61a1a/04132023082802AM/FB leads - Copy.xml
Thanks
Naimish MakwanaPosted Apr 13, 2023, 8:24 AM
The "Invalid file signature" error suggests that the file you are trying to read is not in the expected format, or it is corrupted.
One possible reason for this error is that you are trying to open an XML file with an Excel reader. The XML format and Excel format are different, and you cannot simply change the file extension from ".xml" to ".xls" to convert an XML file to an Excel file. Instead, you need to use a library or tool that can convert the XML data to an Excel format.
If you want to read an XML file directly, you can use the
XmlReaderclass instead of theExcelReaderclass. Here is an example code snippet that shows how to read an XML file into aDataTableusingXmlReader:Naimish MakwanaPosted Apr 13, 2023, 8:13 AM
Try below code:
Thanks
Ramco RamcoPosted Apr 13, 2023, 8:04 AM
Hi AMit
On thsi code it gives Invalid file signature
FileUpload1.SaveAs(FilePath);
UploadSave(Utility.ReadExcelFile(FilePath));
Amit MohantyPosted Apr 13, 2023, 7:58 AM