1

I am trying to open a word document but it doesn't work as i can only save the document, not open it.

I'm getting the error below when trying to open a document: enter image description here

Do i need to make any changes to something so that users are able to open document in SharePoint?

Right now i am only able to save the document.

object missing = Missing.Value; 
object start1 = 0;

var wordApp = new Microsoft.Office.Interop.Word.Application();

var myDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges; 
Range rng = myDoc.Range(ref start1, ref missing);

const char newLine = (char)11; 
myDoc.SaveAs(ref fs, 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, ref missing, ref missing); 
myDoc.Save();

myDoc.Close(ref doNotSaveChanges, ref missing, ref missing);

wordApp.Quit(ref doNotSaveChanges, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myDoc);   
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
GC.Collect();

2 Answers 2

1

In order to use Office Interop, in your case for Word automation you would need to have Office installed on the Server - it looks like the code you are trying is actually failing due to missing of assemblies.

It is not at all recomanded as strategy, but rather the use of OpenXML SDK 2.0 - compatible with SharePoint 2010 (or v2.5 for SharePoint 2013) - you files must be saved as .docx

OpenXml can allow manipulation of most Office files, and for Server environments it could be very well combined with Word Automation Services which allow for conversion of Word documents towards other formats.

1

You have to check DCOM-setting in Component Service console of windows server. Find there Computers->My Computer->DCOM Config->Microsoft Office Word Document->Identity and set it to The launching user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.