简体   繁体   中英

Could not load file or assembly 'office, Version=12.0.0.0, Culture=neutral

I want to read text from a Word file. Its working properly on localhost but when I run it online then I get this error:

Could not load file or assembly 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

My code:

Application Objword = new Application();
Document objdoc = new Document();
dynamic FilePath = fileLoc;
dynamic NA = System.Type.Missing;
objdoc = Objword.Documents.Open(ref FilePath, ref NA, ref NA, ref NA, ref NA,ref NA, ref NA, ref NA, ref NA,
        ref NA, ref NA, ref NA, ref NA,ref NA, ref NA, ref NA);
StringBuilder sb = new StringBuilder();
for (int Line = 0; Line < objdoc.Paragraphs.Count; Line++)
{
    string Filedata = objdoc.Paragraphs[Line + 1].Range.Text.Trim();

    if (Filedata != string.Empty)
    {
        //Append word files data to stringbuilder
        sb.AppendLine(Filedata);
    }
}
((_Document)objdoc).Close();
((_Application)Objword).Quit();
TextBox1.Text = Convert.ToString(sb);

I have also placed dll file in bin folder with same version but still getting error.

It seems to be a very peculiar issue with running office on a server. Suggestions are you would need to install the same version of office on your server as that in your development machine. Because, apart from the interop dll, you would also require more than just the DLL.

Additionally, step through your code and check where it fails, probably, the interop is returning an error somewhere in your code and is returning another error.

For example, if the error message is in the first line, then it is related to the DLL file, however, if it fails somewhere down, then that call is giving the error and not the actual loading of the DLL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM