Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
string str = Server.MapPath(FileUpload1.FileName);
               string ext = System.IO.Path.GetExtension(str);
               FileUpload1.SaveAs(Server.MapPath("Bin\\") + FileUpload1.FileName);
               string p = Server.MapPath("Bin\\") + FileUpload1.FileName;
 Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
                    object missing = System.Reflection.Missing.Value;
                    //object path = @str;
                    object path = @p;
                    object readOnly = false;
                    Microsoft.Office.Interop.Word.Document doc = word.Documents.Open
                        (
                        ref path,
                        ref missing,
                        ref readOnly,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing
                        );
                    string text = "";
                    for (int i = 0; i < doc.Paragraphs.Count; i++)
                    {
                        text += "\r\n" + doc.Paragraphs[i + 1].Range.Text.ToString();
                    }
                    TextBox1.Text = text.ToString();
                    word.Documents.Close(ref missing, ref missing, ref missing);


it opens a ms word window when it reach
word.Documents.Close(ref missing, ref missing, ref missing);
all over its working correctly only this is the issue.
Posted
Comments
Richard Deeming 9-Oct-15 8:23am    
Considerations for server-side Automation of Office[^]:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

The OpenXML SDK[^] should let you open and read Word documents on the server without using Office interop, and without having to install Office on the server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900