1

Below is my code on click to button. If I will run project using localhost it will open word document very well but when I am going to host this project on IIS and try to open it from another machine by IP it will transfer my page to error message.

Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

object file = "D:\\poForM.docx";

object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
object readOnly = false;
object visible = true;
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref file, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, visible, ref missing, ref missing, ref missing, ref missing);
aDoc.Activate();
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • using anchor tag it will ask for download but i would like to open the document and user can edit the document and user can save that document which upodate save on server – Shivam Akhani Dec 31 '14 at 09:39

2 Answers2

0

Your code is relying on there being an instance of Microsoft Word on the server (Microsoft.Office.Interop.Word.ApplicationClass)... and having the object file at a specified location on the server.

If I understand correctly what you are trying to do you want to host the Word document on your IIS server but download it onto the local machine for editing..

You can do this by providing a link in your Web page to where the Word doc is, for example:

<a href="/path/on/the/server/to/my/word/document.docx">Open Word Document</a>

Then when you click the link the browser will download the doc and open it in Word (assuming it's installed locally)

Of course if I've completely misunderstood what you're trying to do feel free to comment....

  • using anchor tag it will ask for download but i would like to open the document and user can edit the document and user can save that document which upodate save on server – Shivam Akhani Dec 31 '14 at 09:39
0

I believe you want to achieve SharePoint alike behaviour where the user can open the file and then save it back to server. Here is a similar thread Possible for Word to edit documents directly off an web server without Sharepoint? . The only bad thing about this solution is that AFAIK it is working only in IE. You can also try new ActiveXObject("Word.Application");instead of the new ActiveXObject("SharePoint.OpenDocuments");

Community
  • 1
  • 1
Ciamas
  • 41
  • 2
  • 7
  • is there any another way for ms word online editor than please suggest.If it will paid than it doesnt mater – Shivam Akhani Dec 31 '14 at 09:41
  • Well, haven't ever been realy interested in the topic to be honest. The first thing that comes to my mind is OneDrive/Office365;) You could server side upload to the OneDrive and then open in browser in online editor (this editor also allows opening in desktop application). I don't know if it is the only solution but it is the only one that comes to my mind now. – Ciamas Dec 31 '14 at 09:50