I am trying to open word document using Word interop service, the file exists and I can see the file on disk and it is opening without any issue. Even I am checking if the file exists on disk before opening the file. Even after this check I am getting error message that file not found, moved, deleted or renamed. Please see the code below.

            var fileNameOnly = Path.GetFileName(templateFilePath);
            foreach (string file in Directory.GetFiles(Path.GetTempPath(), "*.doc"))
                    //Open the doc File
                    FileInfo fileInfo = new FileInfo(file);
                    Object currentfileName = fileInfo.FullName;

                    if (fileInfo.Name.Equals(fileNameOnly))
                        //Console.WriteLine("Creating label document.");
                        // Create new file
                        WORD._Document doc = app.Documents.Open(templateFilePath);

This code is run from Farm WebPart solution on SharePoint 2013 solution and Office 2013 is installed on all WFE servers.

Error message: Sorry, we couldn’t find your file. Is it possible it was moved, renamed or deleted?

I am not able to get resolution for this problem. Please help.

  • While not related to your question, keep in mind that the Interop Assemblies are not designed to be used server-side: support.microsoft.com/en-us/help/257757/…. In addition, it is not supported to install Office client on SharePoint servers as it has conflicting binaries. – Trevor Seward Nov 29 '17 at 16:54
  • I have gone through this article, thanks for reminding about that. I have a console app which does open the document but when I am trying to use same code in custom WebPart it suddenly stops working. Does this means that I cannot use any Interop Assemblies in WebPart code but can use in console application and run on SharePoint server? – Nikhil Chavan Nov 29 '17 at 16:58
  • It's not that you cannot, but you should not as you may run into unexpected issues. But what are you exactly doing that requires you to open Word (how could you do this in an ASP.NET process which contains no Windows Session)? Maybe we can steer you to a better solution. – Trevor Seward Nov 29 '17 at 17:00
  • I have a template file of Word(.doc) and I am filling the template file with actual values from my data source also I am reading files from a library and merging them together in single document, these two things needs to accomplished. Please let me know better solution, it would be really great to have different approach than using Interop assemblies. – Nikhil Chavan Nov 29 '17 at 17:04

You should not use Interop assemblies in an ASP.Net application. You should use Open XML SDK instead. It is very efficient in handling Office documents and works perfect for ASP.NET.


If this answers your question, please mark as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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