how to read word document in ASP.Net & C#

J

Jay

Hi,
I need to read word document file in ASP.net and place it in a text
box .
How to do it ? i tried :

Word.Application app = new Word.ApplicationClass();
object nullobj = System.Reflection.Missing.Value;
object file = @"C:\Suneetha\Ques.doc";
Word.Document doc = app.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string text = data.GetData(DataFormats.Text).ToString();
Console.WriteLine(text);
doc.Close(ref nullobj, ref nullobj, ref nullobj);
app.Quit(ref nullobj, ref nullobj, ref nullobj);

but i got few error :

" No overload for method 'Open' takes '15' arguments "

is there any toehr way to read a word document file ?
waiting for ur replay ,

Thanks,
Jay
 
G

Guest

It sounds like you are real close. How many arguments does the .Open( take
when you delete and the retype the first ( after the open?

If you are pasting code in from a sample on the net, sometimes that doesn't
work. This is because you are using early binding for your Word automation
with the code you have and your .olb may not be the same version the example
was written from.

Opens from version 9 and 11 have different number of arguments. If you are
using 9, you should only have 12 arguments.

Ex)
oWordDoc = WordApplicationInstance.Documents.Open(ref fileName, ref missing,
ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref
missing, ref missing,
ref missing, ref missing, ref missing);

Thanks,

Rob K
 
J

Jayender

U r right Rob,
Here is the code that i did and that might help some one:

Word.ApplicationClass wordApp = new Word.ApplicationClass();
string filePath = inputbox.Value;
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(ref file, ref
nullobj, ref nullobj,
ref nullobj, ref nullobj,
ref nullobj,
ref nullobj, ref nullobj,
ref nullobj,
ref nullobj, ref nullobj,
ref nullobj);

Word.Document doc1 = wordApp.ActiveDocument;
string m_Content = doc1.Content.Text;
m_Resume.Text = m_Content;
doc.Close(ref nullobj, ref nullobj, ref nullobj);

it works cool ..
Guys,any doubs do message me ...

Ciao,
Jayender
 
G

Guest

Nice job! If you want, you can click the Yes button under the "Did this
answer you question" note under the last post I made so people know this
thread is answered.

Happy Programming! :~}

Rob K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top