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