title: using Microsoft.Office.Interop Word and Excel
body: <p>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</p>
  
  <pre><code>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 &lt; docs.Paragraphs.Count; j++)
    {
      totaltext += " \r\n " + docs.Paragraphs[j + 1].Range.Text.ToString();
    }
    docs.Close();
    newApp.Quit();
    return totaltext;
  }
  </code></pre>
  
  <p>I was getting this exception</p>
  
  <blockquote>
    <p>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)).</p>
  </blockquote>
  
  <p>I fixed it by following <a href="https://stackoverflow.com/questions/3477086/accessing-office-word-object-model-through-asp-net-results-in-failed-due-to-the">this post</a>
  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</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>I read solution to give rights to folder, and also create Desktop folder inside system32 <a href="http://dawnsend.blogspot.com/2010/06/interopservicescomexception-0x800a03ec.html" rel="nofollow noreferrer">Here</a>,both solutions not worked for me :(
  The issue is arising only when I am publishing it</p>