I Want to convert xml files to Excel using asp .net c# so I am reading file as
xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());
but It is giving error
{"Could not find file 'C:\\Program Files (x86)\\IIS Express\\Product.xml'.":"C:\\Program Files (x86)\\IIS Express\\Product.xml"}
My file is present in
C:\Program Files (x86)\IIS Express
also it is giving error at following location
releaseObject(xlApp);
releaseObject(xlWorkBook);
releaseObject(xlWorkSheet);
does not exist in current context
What I have tried:
on button click I have following code to convert excel
protected void Button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
DataSet ds = new DataSet();
XmlReader xmlFile;
int i = 0;
int j = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
{
xlWorkSheet.Cells[i + 1, j + 1] = ds.Tables[0].Rows[i].ItemArray[j].ToString();
}
}
xlWorkBook.SaveAs("D\\filename.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlApp);
releaseObject(xlWorkBook);
releaseObject(xlWorkSheet);
Response.Write("File has saved in D drive");
}
also I want to know can I give another path for product.xml i.e can I put it on another drive and give that path how?
xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());