I am using Microsoft.Office.Interop, for scanning word and excel files using C#,I am taking file as input from user, saving it on local directory then scanning it Interop library. Its working fine on my local publish, However when I published it on server its not scanning Word or Excel Files. I have MS-Office installed on my Server, the same version which I have on my PC. What else I need to do? I have copied the required DLL's in my bin Directory. This is how I am reading word file
public static string word_to_text(string source)
{
Word.Application newApp = new Word.Application();
object Source = source;
object Unknown = Type.Missing;
object miss = System.Reflection.Missing.Value;
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = newApp.Documents.Open(ref Source, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int j = 0; j < docs.Paragraphs.Count; j++)
{
totaltext += " \r\n " + docs.Paragraphs[j + 1].Range.Text.ToString();
}
docs.Close();
newApp.Quit();
return totaltext;
}
I was getting this exception
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I fixed it by following this post However now I am having issue with excel and word files. In case of Word files,its not reading the file from above code,docs object is appearing to be null. In case of Excel Its showing exception
Microsoft Office Excel cannot access the file 'myfile path'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.
I read solution to give rights to folder, and also create Desktop folder inside system32 Here,both solutions not worked for me :( The issue is arising only when I am publishing it