We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,745 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Keyword from a word file without using interop.word....

I want to read data from word file without using interop.word dll..Because i don't want to install word in every server....Is it possible to deploy interop.word without installation of word in iis..If not provide a solution to read word file without it with complete code....I tried with open xml sdk but in some word files file contains corrupted data msg shown....My code as follows:

  private void SearchWord(string[] str1)
        {
            string filename1 = "";
            string randomName = "";
            string fname = "";
            Session["cids"] = "";
            object missingType = Type.Missing;
            object readOnly = true;
            object isVisible = false;
            object documentFormat = 8;
            string s12 = "select id,docfilename from Uploadeddocsmaster";
            dt = cn.viewdatatable(s12);
            int dtcount = dt.Rows.Count * 2;
            string[] ids = new string[dtcount];

            for (int k = 0; k < dt.Rows.Count; k++)
            {
                string id = dt.Rows[k]["id"].ToString();
                filename1 = dt.Rows[k]["docfilename"].ToString();
                string fileName = Server.MapPath("~/UploadedFiles/") + filename1;
                string ext = Path.GetExtension(fileName);
                if (ext == ".doc" || ext == ".docx")
                {

                    Application applicationclass = new Application();
                    string[] crefids = filename1.Split('.');
                    for (int mj = 0; mj < crefids.Length; mj++)
                    {
                        randomName = crefids[0].ToString();
                    }

                    object Source = fileName;
                    object Target = Server.MapPath("~/Temp/" + randomName + ".txt");
                    fname = Target.ToString();
                    // object Target = @"D:\Alex\ResumeManager Dec 6,2012\ResumeManager\Uploaddocs\test1.txt";

                    //Upload the word document and save to Temp folder
                    // FileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));


                    applicationclass.Documents.Open(ref Source,
                                                    ref readOnly,
                                                    ref missingType, ref missingType, ref missingType,
                                                    ref missingType, ref missingType, ref missingType,
                                                    ref missingType, ref missingType, ref isVisible,
                                                    ref missingType, ref missingType, ref missingType,
                                                    ref missingType, ref missingType);
                    applicationclass.Visible = false;
                    Document document = applicationclass.ActiveDocument;
                    object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatUnicodeText;

                    //Save the word document as HTML file
                    document.SaveAs(ref Target, ref format, ref missingType,
                                    ref missingType, ref missingType, ref missingType,
                                    ref missingType, ref missingType, ref missingType,
                                    ref missingType, ref missingType, ref missingType,
                                    ref missingType, ref missingType, ref missingType,
                                    ref missingType);

                    //Close the word document
                    document.Close(ref missingType, ref missingType, ref missingType);


                    foreach (string str in str1)
                    {

                        using (StreamReader sr = new StreamReader(fname))
                        {

                            if (string.IsNullOrEmpty(str) == false)
                            {
                                string szReadAll = sr.ReadToEnd().ToLower();
                                if (Regex.IsMatch(szReadAll, str.ToLower()))
                                {
                                    if (!ids.Contains(id))
                                    {
                                        ids[mn] = id;
                                    }
                                    Session["ids"] = ids;
                                }
                            }
                        }

                    }
                }

                else if (ext == ".pdf")
                {
                    string randomName1 = DateTime.Now.Ticks.ToString();
                    string fname1 = "";



                    object Target1 = Server.MapPath("~/Temp/" + randomName1 + ".txt");
                    fname1 = Target1.ToString();

                    PDDocument doc = PDDocument.load(fileName);
                    PDFTextStripper stripper = new PDFTextStripper();
                    string s = stripper.getText(doc).ToLower();
                    System.IO.StreamWriter LogFile = new System.IO.StreamWriter(fname1, true);
                    LogFile.WriteLine(s);
                    LogFile.Close();
                    foreach (string str in str1)
                    {
                        using (StreamReader sr = new StreamReader(fname1))
                        {

                            if (string.IsNullOrEmpty(str) == false)
                            {
                                string szReadAll = sr.ReadToEnd().ToLower();
                                if (Regex.IsMatch(szReadAll, str.ToLower()))
                                {
                                    if (!ids.Contains(id))
                                    {
                                        ids[mn] = id;
                                    }
                                    Session["ids"] = ids;
                                }
                            }
                        }

                    }
                }
                mn++;

            }




            //Upload the word document and save to Temp folder
            // FileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));

        }
2
Contributors
3
Replies
20 Hours
Discussion Span
4 Months Ago
Last Updated
4
Views
korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I'd say your best hope is http://netoffice.codeplex.com/

Good luck! =)

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

Please provide a complete code so that it would be more easy to understand...

korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
// initialize NetOffice, must be called 1 times in your application before use
LateBindingApi.Core.Factory.Initialize();

// open word and an existing document
Word.Application wordApplication = new Word.Application();
Word.Document newDocument = wordApplication.Documents.Open(@"C:\myWordFile.doc");

// read text of document
string plainContent = newDocument.Content.Text;

// close word and dispose reference 
wordApplication.Quit();
wordApplication.Dispose();

Please, don't be lazy and please search in the site that I posted.

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1049 seconds using 2.69MB