i am trying to read a work microsoft 2010 word document in asp.net, it works fine in local host i mean when i debug application, but when i host it in iis gives errorError
Error: KushL7DocParser / Message :Object reference not set to an instance of an object. / Data :System.Collections.ListDictionaryInternal / Exception: / Target: Void btnPreview_Click(System.Object, System.EventArgs)
please help me
Thanks
Reading word document giving error in aps.net
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Oct 14, 2013, 7:56 PM EDT
txtPreview.Visible = true; if (FileUpload1.HasFile) { Microsoft.Office.Interop.Word.ApplicationClass WApplication = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document(); try { //FileUpload(); FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName)); object filename = Server.MapPath(FileUpload1.FileName); Label6.Text = Server.MapPath("~/") + uploadfile + " Preview Started1......"; //object upfile = Server.MapPath("~/") + uploadfile; object upfile = filename; object nullobj = System.Reflection.Missing.Value; doc = WApplication.Documents.Open(ref upfile, ref nullobj, ref nullobj,ref nullobj, ref nullobj, ref nullobj, ref nullobj); Label6.Text = Server.MapPath("~/") + uploadfile + " Preview Started3......"; if (doc != null) { Label6.Text = Convert.ToString(doc.Name) + " Activation Started1......"; doc.Activate(); txtPreview.Text = doc.Content.Text; Label7.Text = "File Reading Successful"; //doc.Close(ref nullobj, ref nullobj, ref nullobj); } else { Label7.Text = doc.Content + "File Reading Failed"; // System.Runtime.InteropServices.Marshal.ReleaseComObject(WApplication); } } catch (Exception Ex) { Label7.Text = Ex.Source; txtPreview.Text = "Error: " + Ex.Source + " / Message :" + Ex.Message + " / Data :" + Ex.Data + " / Exception: " + Ex.InnerException + " / Target: " + Ex.TargetSite; } finally { if (doc != null) { doc.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(doc); } WApplication.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(WApplication); File.Delete(Server.MapPath(FileUpload1.FileName)); } }Sunny SharmaRank #223 · 11.1K pointsPosted Oct 14, 2013, 8:59 PM EDT
Your code works all fine here. Suggest you to put breakpoint, step over one by one and check what line of code is raising the error.
Thanks
Former memberPosted Oct 14, 2013, 11:17 PM EDT
1 short reply
Sunny SharmaRank #223 · 11.1K pointsPosted Oct 13, 2013, 11:54 PM EDT