asp.net mvc 4 - Unable to read word file in mvc 4 -
i'm using following code read word file uploaded on (local) website.
list<string> readwordfile(string path) { application word = new application(); document doc = new document(); ((_document)doc).close(); ((_application)word).quit(); list<string> data = new list<string>(); try { object filename = path; // define object pass api missing parameters object missing = system.type.missing; doc = word.documents.open(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); string read = string.empty; (int = 0; < doc.paragraphs.count; i++) { string temp = doc.paragraphs[i + 1].range.text.trim(); if (temp != string.empty) data.add(temp); } } catch (exception) { } { ((_document)doc).close(); ((_application)word).quit(); } return data; }
this error:
the object invoked has disconnected clients. (exception hresult: 0x80010108 (rpc_e_disconnected))
i'm calling function controller. if i'm reading word file wrong way, what's right way?
don't close word before start doing something:
remove line 6 , 7:
((_document)doc).close(); ((_application)word).quit();
you in finaly section, no need put @ end.
Comments
Post a Comment