c# - using Microsoft.Office.Interop Word and Excel -
i using microsoft.office.interop, scanning word , excel files using c#,i taking file input user, saving on local directory scanning interop library. working fine on local publish, when published on server not scanning word or excel files. have ms-office installed on server, same version have on pc. else need do? have copied required dll's in bin directory. how 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 = ""; (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 getting exception
retrieving com class factory component clsid {000209ff-0000-0000-c000-000000000046} failed due following error: 80070005 access denied. (exception hresult: 0x80070005 (e_accessdenied)).
i fixed following this post having issue excel , word files. in case of word files,its not reading file above code,docs object appearing null. in case of excel showing exception
microsoft office excel cannot access file 'myfile path'. there several possible reasons: • file name or path not exist. • file being used program. • workbook trying save has same name open workbook.
i read solution give rights folder, , create desktop folder inside system32 here,both solutions not worked me :( issue arising when publishing it
you should not use office automation in server. 1 thread can access word @ time, it's slow relative other options, , word not made server-side execution.
much better use openxml sdk:
http://www.microsoft.com/en-us/download/details.aspx?id=5124
or other wrapper:
http://www.codeproject.com/articles/87711/manipulate-docx-with-c-without-microsoft-word-inst
if feel absolutely must use office automation on server (and shouldn't), @ least put in separate process , enque requests other process. way can ensure 1 request being processed @ time, can safely grant other process permissions needed, , if word halts can kill , secondary process.
Comments
Post a Comment