You must Sign In to post a response.
  • Category: Windows

    how to read .doc file in windows application

    Hi All,

    Please tell me

    how to access/read the particular text(name,emailid,dob of resume) of the word document in C#.Net windows application.

    Thank you

  • #222968
    Here is the code that helps to read any document (like .doc, .rtf , txt )
    from specified location. This is a web based application and this code is
    written in C# as code behind in ASP.Net 2.0, where the word document
    is hard to upload from client side. Here is the code that uploads the
    document file and stores it into a string and from that I have placed
    that string into a textbox.

    The First Step is that, we need to add a COM reference (that's how we
    need to define the word application) to the project by right clicking in
    the solution explorer on References->Add Reference. Click on the COM
    tab and look for the Microsoft Word 9.0 Object Library. Click Select
    and OK.

    Now u need to add the line <identity impersonate="true"/>



    <identity impersonate="true"/>

    in your web.config .

    Then here is the code u need to add in your summit button: :

    protected void Submit1_ServerClick(object sender, EventArgs e)


    Word.ApplicationClass wordApp = new Word.ApplicationClass();

    // Input box is used to get the path of the file which has to be
    uploaded into textbox.

    string filePath = inputbox.Value;

    object file = filePath;

    object nullobj = System.Reflection.Missing.Value;

    // here on Document.Open there should be 9 arg.

    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);

    // Here the word content is copeied into a string which helps to
    store it into textbox.

    Word.Document doc1 = wordApp.ActiveDocument;

    string m_Content = doc1.Content.Text;

    // the content is stored into the textbox.

    m_Textbox.Text = m_Content;

    doc.Close(ref nullobj, ref nullobj, ref nullobj);


  • #222976

    Delete Attachment

  • #223003
    add microsoft object library
    then imports

    Dim openFileDialog As New OpenFileDialog
    If openFileDialog.ShowDialog() = DialogResult.OK Then
    'Dim filename As String = openFileDialog.FileName
    Dim a() As Object = {}
    Dim filename As Object = openFileDialog.FileName
    Dim wordType As Type = Type.GetTypeFromProgID("Word.Application")
    Dim wordApplication As Object = Activator.CreateInstance(wordType)
    wordType.InvokeMember("Visible", Reflection.BindingFlags.SetProperty, Nothing, wordApplication, New Object() {False})
    Dim wordDocuments As Object = wordType.InvokeMember("Documents", Reflection.BindingFlags.GetProperty, Nothing, wordApplication, a)
    Dim wordDocument As Object = wordType.InvokeMember("Open", Reflection.BindingFlags.InvokeMethod, Nothing, wordDocuments, New Object() {filename})
    Dim activeWindow As Object = wordDocument.[GetType]().InvokeMember("ActiveWindow", Reflection.BindingFlags.GetProperty, Nothing, wordDocument, Nothing)
    Dim selection As Object = activeWindow.[GetType]().InvokeMember("Selection", Reflection.BindingFlags.GetProperty, Nothing, activeWindow, Nothing)
    selection.[GetType]().InvokeMember("WholeStory", Reflection.BindingFlags.InvokeMethod, Nothing, selection, Nothing)
    selection.[GetType]().InvokeMember("Copy", Reflection.BindingFlags.InvokeMethod, Nothing, selection, Nothing)
    wordDocument.[GetType]().InvokeMember("Close", Reflection.BindingFlags.InvokeMethod, Nothing, wordDocument, Nothing)
    wordApplication.[GetType]().InvokeMember("Quit", Reflection.BindingFlags.InvokeMethod, Nothing, wordApplication, Nothing)
    Dim data As IDataObject = Clipboard.GetDataObject()
    Dim text As String = data.GetData(DataFormats.Text).ToString()
    RichTextBox1.Text = text


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.