I want code to copy word text content into texbox using c# code in web application

right now i have code for windows application.

using Microsoft.Office.Interop.Word;

private void readFileContent(string path)
        Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
        object file = path;
        object nullobj = System.Reflection.Missing.Value;

        Microsoft.Office.Interop.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);
        IDataObject data = Clipboard.GetDataObject();
       textbox1.Text = data.GetData(DataFormats.Text).ToString();
        doc.Close(ref nullobj, ref nullobj, ref nullobj);
        wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);


This code is working in windows application....Clipbord is not there in web application....
so how to do in web application

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

7 Years
Discussion Span
Last Post by aravinda reddy

Do you want to this operation in client side or server side?

Since it is a web application, you can't use the above C# code at client side. It can be done using JavaScript only.

You can try to use object.execCommand javascript method to paste the text from clipboard to the current object such as TextBox.

For example,

function PasteTextFromClipboard()
            var strText = document.getElementById('textArea1').createTextRange();

In case if you want to do this operation in server side, check the following article. The C# code uploads a word document file and stores it into a string and from that it is placed that string into a textbox.

Read any document (like .doc, .rtf , txt ) in ASP.Net , C#


Don't use Clipboard object. Read content of doc using,

string txt=doc.Content.Text;

Thanks it helped me...U r right

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.