locked
Urgent!!! --- problem while export to EXCEL - " The XML page cannot be displayed " RRS feed

  • Question

  • User-1285090017 posted

    Error Message:

    =================================================

    The XML page cannot be displayed <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later. <o:p></o:p>

    The server did not understand the request, or the request was invalid. Error processing resource 'http://www.w3.org/TR/xhtm...<o:p></o:p>

    ===============================================

     

    MY C# code: 

        

    ExportEquipment export = new ExportEquipment();<o:p></o:p>

              string path1 = export.ExportEquipmentData(version, 0, Movesid);<o:p></o:p>          if (File.Exists(path1))<o:p></o:p>          {<o:p></o:p>            string name = Path.GetFileName(path1);<o:p></o:p>            Response.ContentType = "application/ms-excel";<o:p></o:p>            Response.WriteFile(path1);<o:p></o:p>            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; FileName=" + name);<o:p></o:p>            threadEnd = true;<o:p></o:p>            Response.End();<o:p></o:p>          }<o:p></o:p>

     

    public string ExportEquipmentData(string version, int MyItemNo, string Movesid)<o:p></o:p>    {<o:p></o:p>        try<o:p></o:p>        {<o:p></o:p>          CheckExcellProcesses();<o:p></o:p><o:p> </o:p>            version1 = "Exportequipment" + version + ".xls";<o:p></o:p>            string path = System.Web.HttpContext.Current.Server.MapPath("Template/equipment_upload" + version + ".xls");<o:p></o:p>            string existingVersion = System.Web.HttpContext.Current.Server.MapPath("Template/" + version1);<o:p></o:p>            if (File.Exists(existingVersion))<o:p></o:p>            {<o:p></o:p>                File.Delete(existingVersion);<o:p></o:p>            }<o:p></o:p>            object paramMissing = Type.Missing;<o:p></o:p>            object Readonly = false;<o:p></o:p>            logo.LogExceptionNew(exp.Message.ToString(), System.Web.HttpContext.Current.Server.MapPath("Template/"), "excelApplication.Workbooks.Open");<o:p></o:p>            excelWorkBook = excelApplication.Workbooks.Open(@path, Type.Missing, Readonly, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);<o:p></o:p>            excelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelWorkBook.ActiveSheet;<o:p></o:p>            WriteToExcel(MyItemNo,Movesid); // in this function writting to Excel is done<o:p></o:p>            excelWorkBook.SaveAs(System.Web.HttpContext.Current.Server.MapPath("Template/" + version1), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);<o:p></o:p>        }<o:p></o:p>        catch (Exception ex)<o:p></o:p>        {<o:p></o:p>            logo.LogExceptionNew(ex.Message.ToString(), System.Web.HttpContext.Current.Server.MapPath("Template/"), "Exception");<o:p></o:p>        }<o:p></o:p>        finally<o:p></o:p>        {<o:p></o:p>          <o:p></o:p>          try<o:p></o:p>          {<o:p></o:p>            bool flag = KillExcel();<o:p></o:p>          }<o:p></o:p>          catch (Exception ex)<o:p></o:p>          {<o:p></o:p><o:p> </o:p>            //<o:p></o:p>          }<o:p></o:p><o:p> </o:p>          try<o:p></o:p>          {<o:p></o:p>            while (Marshal.ReleaseComObject(excelWorkBook) > 0)<o:p></o:p>              //excelApplication.Workbooks.Close();<o:p></o:p>              Marshal.ReleaseComObject(excelWorkBook);<o:p></o:p>            while (Marshal.ReleaseComObject(excelApplication) > 0)<o:p></o:p>              //excelApplication.Quit();<o:p></o:p>              Marshal.ReleaseComObject(excelApplication);<o:p></o:p><o:p> </o:p>            //if (excelApplication.Workbooks != null)<o:p></o:p>            //  excelApplication.Workbooks.Close();<o:p></o:p>          }<o:p></o:p>          catch (Exception ex)<o:p></o:p>          {<o:p></o:p><o:p> </o:p>            //<o:p></o:p>          }<o:p></o:p>          try<o:p></o:p>          {<o:p></o:p>            excelWorkBook = null;<o:p></o:p>            excelApplication = null;<o:p></o:p>            <o:p></o:p>            GC.GetTotalMemory(false);<o:p></o:p>            GC.Collect();<o:p></o:p>            GC.WaitForPendingFinalizers();<o:p></o:p>            GC.Collect();<o:p></o:p>            GC.GetTotalMemory(true);<o:p></o:p>          }<o:p></o:p>          catch (Exception ex)<o:p></o:p>          {<o:p></o:p><o:p> </o:p>            //<o:p></o:p>          }<o:p></o:p>        }<o:p></o:p>        HttpContext.Current.Response.Clear();<o:p></o:p>        string path1 = System.Web.HttpContext.Current.Server.MapPath("Template/" + version1);<o:p></o:p><o:p> </o:p>        return @path1;<o:p></o:p>    }<o:p></o:p>

     

     

    Please help some one!!!

     

    Urgent!!!

    Regards

     

    Tuesday, April 7, 2009 5:58 AM

Answers

All replies

  • User-518513732 posted

    http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx

     http://www.codeguru.com/forum/showthread.php?t=339912

    http://www.codeproject.com/KB/cs/export2excel.aspx

    Tuesday, April 7, 2009 8:44 AM
  • User-1659704165 posted

    Hi,

    Upload The Excel File....
    Modify Excel as U want....

    And Take Excel Data In  Dataset...
    And Write That Datset to .Xml file..
    There Would be No error..

    In Current Situation there Would be Chances That ...
    U may be entering META Tag Such as <,> etc..

    So Kindly write XMl from datset..

    Hope it helps

     

    Tuesday, April 7, 2009 8:47 AM
  • User-1285090017 posted

    Hi,

    Upload The Excel File....
    Modify Excel as U want....

    And Take Excel Data In  Dataset...
    And Write That Datset to .Xml file..
    There Would be No error..

    In Current Situation there Would be Chances That ...
    U may be entering META Tag Such as <,> etc..

    So Kindly write XMl from datset..

    Hope it helps

     

    You are correct, I would like to know how to convert dataset to XML file.

    Can you give me any link? please, it would help me!!!

     

     

     

    Tuesday, April 7, 2009 10:04 AM
  • User-1659704165 posted

    Hi,

    http://msdn.microsoft.com/en-us/library/system.data.dataset.getxml.aspx

    Check Above Link...

    Hope It helps

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 8, 2009 3:01 AM