I want to read from a doc file in my c# code after uploading through FIleuploader control.

I want to upload a doc file into c# code and read its contents and then store it in the database.
SukeshjphAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PlatoConsultantCommented:
if u want to use the MS office 2007 and 2003 formats then u have to use the 3rd party components like txtextcontrol they work in both client side and server side....

  easily bind to database Blob columns and work fine

0
PlatoConsultantCommented:
if u don't want to process the document just want to upload and save it then

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=112

this tutorial provides details for it

private void btnSubmit_Click(object sender, System.EventArgs e)
{
            
    string strDocExt;
    //strDocType to store Document type which will be Stored in the Database
    string strDocType;
            
    //Will be used to determine Document length
    int intDocLen;
 
    //Stream object used for reading the contents of the Uploading Documnet
    Stream objStream;
 
    SqlConnection BooksConn;
    SqlCommand cmdUploadDoc;
 
    if(IsValid)
    {
        if(txtFileContents.PostedFile != null)
        {
            //Determine File Type
            strDocExt = CString.Right
                (txtFileContents.PostedFile.FileName,4).ToLower();
            switch(strDocExt)
            {
                case ".doc":
                strDocType = "doc";
                break;
                
                case ".ppt":
                strDocType = "ppt";
                break;
                
                case ".htm":
                strDocType = "htm";
                break;
                
                case ".html":
                strDocType = "htm";
                break;
                
                case ".jpg":
                strDocType = "jpg";
                break;
                
                case ".gif":
                strDocType = "gif";
                break;
            
                default:
                strDocType = "txt";
                break;
            }
            //Grab the Content of the Uploaded Document
            
            intDocLen = txtFileContents.PostedFile.ContentLength;
            //buffer to hold Document Contents
            byte[] Docbuffer = new byte[intDocLen];
 
            //InputStream:
            //Gets a Stream object which points to an uploaded Document; 
            //to prepare for reading the contents of the file.
            objStream = txtFileContents.PostedFile.InputStream;
 
            //Store the Content of the Documnet in a buffer
            //This buffer will be stored in the Database
            objStream.Read(Docbuffer ,0,intDocLen);
 
            //Add Uploaded Documnet to Database as Binary
            //You have to change the connection string
            BooksConn = new 
                SqlConnection("Server=Server;UID=sa;Database=Books");
 
            //Setting the SqlCommand
            cmdUploadDoc = new 
                    SqlCommand("uSP_BooksUploadFile",BooksConn);
            cmdUploadDoc.CommandType = CommandType.StoredProcedure;
            cmdUploadDoc.Parameters.Add("@Title ",SqlDbType.VarChar,200);
            cmdUploadDoc.Parameters.Add("@Doc",SqlDbType.Image);
            cmdUploadDoc.Parameters.Add("@DocType",SqlDbType.VarChar,4);
            cmdUploadDoc.Parameters[0].Value = txtTitle.Text;
            cmdUploadDoc.Parameters[1].Value = Docbuffer ;
            cmdUploadDoc.Parameters[2].Value = strDocType;
 
            BooksConn.Open();
            cmdUploadDoc.ExecuteNonQuery();
            BooksConn.Close();
        }//End of if(txtFileContents.PostedFile != null)
    }//End Of if(IsValid)
}//End of Method btnSubmit_Click
 
<form id="frmUpload" method="post" enctype="multipart/form-data" runat="server">
    <span>Title</span><br>
    <asp:textbox id="txtTitle" runat="server" EnableViewState="False"></asp:textbox>
    <asp:requiredfieldvalidator id="valrTitle" runat="server" ErrorMessage="* 
Required" ControlToValidate="txtTitle">* Required</asp:requiredfieldvalidator>
    <br>
    <br>
    <span>Docutment to Upload</span><br>
    <input id="txtFileContents" type="file" runat="server" NAME="txtFileContents">
    <br>
    <br>
    <asp:button id="btnSubmit" Text="Submit" Runat="server"></asp:button>
</form>

Open in new window

0
PlatoConsultantCommented:
Aspose.Word is another commercial component to use it server

Aspose.Word is a .Net Word presentations component which enables you to read and write Word documents without utilizing Microsoft Word. Avoid Microsoft Word automation in your .Net applications. Design report or template documents in the familiar environment of your Microsoft Word. Populate the documents with your data using just a few lines of code. Generate thousands of Word documents such as reports, letters, invoices, faxes on the server.The latest release added more properties to the FormField class; Significantly improved functionality of find and replace (Range.Replace);etc.
0
PlatoConsultantCommented:
if u want to go the hard way then u can try Microsoft Word Automation to use its features but its performance is not as good as txtTextcontrol or aspose.word
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SukeshjphAuthor Commented:
My requirement is something like this....I want to open a doc file after uploading and read it and find out some required keywords in this doc file...how can i do it using filestream etc.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.