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.
Microsoft.Office.Interop
in a server environment is not recommended (since it is very prone to errors) and also is not supported by Microsoft (see this link: Considerations for server-side Automation of Office). You should probably look into using some kind of library like OpenXML to manipulate the office files on the server. – bassfader