Skip to content

Reading word document giving error in aps.net

Asked Oct 11, 2013, 3:33 AM EDT4 answers
Share
LinkedInX
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

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi Sunny this is my code below
    C#
    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, ref nullobj, ref nullobj,
                                                          ref nullobj, ref nullobj, ref nullobj,
    C#
                                                          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));
                    }
                }
    0
  • Sunny  Sharma
    0
    Hi Kailash,

    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
    0
  • 0
    no error in the code, but when i host it, it gives error in the server
    0
  • 1 short reply
    • Sunny  Sharma
      0
      Please share your code.
      0