I have a big problem and i hope you can help me out.
I have a PDF file which I split in more files.
Problem: There is a table content (goto page X), but in the new pdf files it doesnt work anymore.
I cant find a solution to copy this table content to the new pdf files.
For your understanding:
I have three pdf files which are equal.
PDF:
Page 1:
Text
Page 2:
Contenttable:
Content x Page 3 (Goto Page 3)
Content x Page 4 ""
content x Page 5 ""
...
...
I put all these pdf files together in one big pdf. (Content table still working)
And now, i will split these back in to single once (Content table not working)
My idea was to export the content table out of the original pdf(Where table content is still working) and to import it in the new once.
But i dont know how.
Second idea: search for keywords in the PDF and change the keyword to an goto local page action.
But i find no solution how i can do this.
However in the end i want to repair the table content in each single pdf file.
any ideas?
code so far:
PdfReader reader = null;
Document sourceDocument = null;
Document remote = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
PdfStamper stamp = null;
Chunk chunk = null;
reader = new PdfReader(path);
Seitenanzahl = reader.NumberOfPages;
sourceDocument = Document(reader.GetPageSizeWithRotation(startpage));
tmp = PdfTextExtractor.GetTextFromPage(reader, startpage);
string[] strsplit = tmp.Split(' ');
vorname = strsplit[4];
nachname = strsplit[5];
ort = strsplit[6];
perso = strsplit[7];
vorname = vorname.Replace("\n", "");
vorname = vorname.Replace(" ", "");
nachname = nachname.Replace("\n", "");
nachname = nachname.Replace(" ", "");
ort = ort.Replace("\n", "");
ort = ort.Replace(" ", "");
perso = perso.Replace("\n", "");
perso = perso.Replace(" ", "");
if (Directory.Exists("test/" + ort))
{
}
else
{
DirectoryInfo di = Directory.CreateDirectory("test/" + ort);
}
outputpdfpath = "test/" + ort + "/" + "p_" + ort + "_" + perso + "_" + vorname.ToLower() + "_" + nachname.ToLower() + "_hj1_booklet_2017" + ".pdf";
pdfCopyProvider = new PdfCopy(sourceDocument,
new FileStream(outputpdfpath, FileMode.Create, FileAccess.ReadWrite));
sourceDocument.Open();
for (int i = startpage; i <= endpage; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
sourceDocument.Close();
reader.Close();
}
Related
Guys am trying to read a csv file from the view, get its data , format it and write back into an empty csv file. presently have been able to achieve the first approach, where the challenge is right now is writing back into an empty csv file created , but it happens that the csv file is always blank after writing in the file. can someone help me out if am missing anything. Note " am just reading and writing the field , have got nothing to do with the hearder because the csv file has no header" Am using csvhelper library.
if (file.ContentLength > 0)
{
string origin = "FORMATERCSV";
string destination = "FORMATERCSVDESTINATION";
string curretnDate = Convert.ToString(DateTime.Now.ToShortDateString().Replace(#"/", "_"));
var fileName = Path.GetFileName(file.FileName);
var pathfound = Server.MapPath( #"/" + "Content" + "/" + origin + "/" + curretnDate + "/");
var pathfoundDestination = Server.MapPath(#"/" + "Content" + "/" + destination + "/" + curretnDate + "/");
if (!Directory.Exists(pathfound)) Directory.CreateDirectory(pathfound);
if (!Directory.Exists(pathfoundDestination)) Directory.CreateDirectory(pathfoundDestination);
string PathToStore = string.Format(#"{0}\{1}", pathfound, fileName);
string PathToStoreDestination = string.Format(#"{0}\{1}", pathfoundDestination, fileName);
var path = Path.Combine(pathfound,fileName);
file.SaveAs(PathToStore);
file.SaveAs(PathToStoreDestination);
System.IO.File.WriteAllText(PathToStoreDestination,string.Empty);
StreamReader sr = new StreamReader(PathToStore);
CsvReader csvread = new CsvReader(sr);
csvread.Read();
var shedule = new Shedule()
{
RSA_PIN = csvread.GetField<string>(0),
EMPLOYEE_NAME = csvread.GetField<string>(1),
EMPLOYER_CONTRIBUTION = csvread.GetField<double>(2),
EMPLOYER_VC = csvread.GetField<double>(3),
EMPLOYEE_CONTRIBUTION = csvread.GetField<double>(4),
EMPLOYEE_VC = csvread.GetField<double>(5),
TOTAL_CONTRIBUTION = csvread.GetField<double>(6),
FROM_MONTH = csvread.GetField<string>(7),
FROM_YEAR = csvread.GetField<string>(8),
TO_MONTH = csvread.GetField<string>(9),
TO_YEAR = csvread.GetField<string>(10),
EMPLOYER_CODE = csvread.GetField<string>(11),
EMPLOYER_NAME = csvread.GetField<string>(12),
PTID = csvread.GetField<string>(13),
RECEIVED_DATE = csvread.GetField<string>(14),
};
StreamWriter sw = new StreamWriter(PathToStoreDestination);
CsvWriter scvwrite = new CsvWriter(sw);
scvwrite.WriteField(shedule.RSA_PIN);
scvwrite.WriteField(shedule.EMPLOYER_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYER_VC);
scvwrite.WriteField(shedule.EMPLOYEE_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYEE_VC);
scvwrite.WriteField(shedule.TOTAL_CONTRIBUTION);
scvwrite.WriteField(shedule.FROM_MONTH);
scvwrite.WriteField(shedule.FROM_YEAR);
scvwrite.WriteField(shedule.TO_MONTH);
scvwrite.WriteField(shedule.TO_YEAR);
scvwrite.WriteField(shedule.EMPLOYER_CODE);
scvwrite.WriteField(shedule.EMPLOYEE_NAME);
scvwrite.WriteField(shedule.PTID);
scvwrite.WriteField(shedule.RECEIVED_DATE);
scvwrite.NextRecord();
scvwrite.Flush();
// Gets field by position returning int
// var field = csv.GetField<int>(0);
}
return RedirectToAction("Index");
}
Several things could actually occure.
1) are you sure the file from the view is not empty?
2) If you use a break point when you instantiate your class Schedule. Do you get the data from the CSV.
3) Do you really need to do this 2 step, wouldn't it be better to directly write the content of the original file to the new file?
4) Last but not least don't forget to close your streamwriter or do like so :
using(var sw = new StreamWriter(PathToStoreDestination)){
CsvWriter scvwrite = new CsvWriter(sw);
scvwrite.WriteField(shedule.RSA_PIN);
scvwrite.WriteField(shedule.EMPLOYER_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYER_VC);
scvwrite.WriteField(shedule.EMPLOYEE_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYEE_VC);
scvwrite.WriteField(shedule.TOTAL_CONTRIBUTION);
scvwrite.WriteField(shedule.FROM_MONTH);
scvwrite.WriteField(shedule.FROM_YEAR);
scvwrite.WriteField(shedule.TO_MONTH);
scvwrite.WriteField(shedule.TO_YEAR);
scvwrite.WriteField(shedule.EMPLOYER_CODE);
scvwrite.WriteField(shedule.EMPLOYEE_NAME);
scvwrite.WriteField(shedule.PTID);
scvwrite.WriteField(shedule.RECEIVED_DATE);
scvwrite.Flush();
}
Doing so you don't even need to specify to flush.
using (var sw = new StreamWriter(PathToStoreDestination))
{
sw.AutoFlush = true;
CsvWriter scvwrite = new CsvWriter(sw);
scvwrite.WriteField(shedule.RSA_PIN);
scvwrite.WriteField(shedule.EMPLOYEE_NAME);
scvwrite.WriteField(shedule.EMPLOYER_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYER_VC);
scvwrite.WriteField(shedule.EMPLOYEE_CONTRIBUTION);
scvwrite.WriteField(shedule.EMPLOYEE_VC);
scvwrite.WriteField(shedule.TOTAL_CONTRIBUTION);
scvwrite.WriteField(shedule.FROM_MONTH);
scvwrite.WriteField(shedule.FROM_YEAR);
scvwrite.WriteField(shedule.TO_MONTH);
scvwrite.WriteField(shedule.TO_YEAR);
scvwrite.WriteField(shedule.EMPLOYER_CODE);
scvwrite.WriteField(shedule.EMPLOYER_NAME);
scvwrite.WriteField(shedule.PTID);
scvwrite.WriteField(shedule.RECEIVED_DATE);
scvwrite.NextRecord();
//scvwrite.Flush();
}
I'm starting to learn c # and Windows form. I create an application that transforms a resx (XML) file into an Excel.
All my code works, my Excel file is created and I can convert it to a resx file.
But, when I open my Excel file, spaces before and after my data has been added like this : Excel cell example. And when I convert it to resx file, it does
Resx file example
Here is my resx => excel code :
//I use a application WindowsForm so any 'LBL' / 'TXT make reference to label or textBox I use them to set file or folder path
private void writeExcel()
{
Dictionary<string, string> dataSave = new Dictionary<string, string>();
var path = LBL_DocumentPath.Text;
XDocument doc = XDocument.Load(path);
IEnumerable<XNode> nodes = doc.Descendants("data");
foreach (XElement node in nodes)
{
string name = node.Attribute("name").Value;
string value = node.Value;
dataSave.Add(name, value);
}
CreateExcel(dataSave);
}
private void CreateExcel(Dictionary<string, string> dico)
{
int i = 1;
FileInfo newFile = new FileInfo(LBL_FolderPath.Text + "/" + TXT_FileName.Text + ".xlsx");
using (ExcelPackage package = new ExcelPackage(newFile))
{
try
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Inventry");
worksheet.Cells[1, 1].Value = "Name";
worksheet.Cells[1, 2].Value = "value";
worksheet.Cells[1, 3].Value = "translation";
foreach (KeyValuePair<string, string> data in dico)
{
string testMessage = String.Format("{0}", data.Value);
string delSpace = testMessage;
Regex regex = new Regex(#"(\s){2,}");
testMessage = regex.Replace(delSpace, "&");
i++;
worksheet.Cells[i, 1].Value = String.Format("{0}", data.Key);
worksheet.Cells[i, 2].Value = String.Format("{0}", testMessage);
worksheet.Cells.AutoFitColumns();
}
package.Save();
MessageBox.Show("File created ! " + LBL_FolderPath.Text + "\\" + TXT_FileName.Text);
}
catch (Exception)
{
MessageBox.Show("File already exist, checks : " + LBL_DocumentPath.Text + "\\" + TXT_FileName.Text);
}
}
}
If you want all my code, I can give you a dropbox link.
Thanks in advance for any help you can give me.
Math.
Ps: My apologies, my English is not very good. I hope you will understand me correctly
Ok a friend give me solution.
It's my regex which does not work so I replace
string testMessage = String.Format("{0}", data.Value);
string delSpace = testMessage;
Regex regex = new Regex(#"(\s){2,}");
testMessage = regex.Replace(delSpace, "&");
by
string testMessage = String.Format("{0}", data.Value);
testMessage = testMessage.Replace("\n",string.Empty);
testMessage = testMessage.Replace("\r", string.Empty);
testMessage = testMessage.Replace(" ", string.Empty);
I am writing a pdf to word converter which works perfectly fine for me. But I want to be able to convert more than one file.
What happens now is that it read the first file and does the convert process.
public static void PdfToImage()
{
try
{
Application application = null;
application = new Application();
var doc = application.Documents.Add();
string path = #"C:\Users\Test\Desktop\pdfToWord\";
foreach (string file in Directory.EnumerateFiles(path, "*.pdf"))
{
using (var document = PdfiumViewer.PdfDocument.Load(file))
{
int pagecount = document.PageCount;
for (int index = 0; index < pagecount; index++)
{
var image = document.Render(index, 200, 200, true);
image.Save(#"C:\Users\chnikos\Desktop\pdfToWord\output" + index.ToString("000") + ".png", ImageFormat.Png);
application.Selection.InlineShapes.AddPicture(#"C:\Users\chnikos\Desktop\pdfToWord\output" + index.ToString("000") + ".png");
}
string getFileName = file.Substring(file.LastIndexOf("\\"));
string getFileWithoutExtras = Regex.Replace(getFileName, #"\\", "");
string getFileWihtoutExtension = Regex.Replace(getFileWithoutExtras, #".pdf", "");
string fileName = #"C:\Users\Test\Desktop\pdfToWord\" + getFileWihtoutExtension;
doc.PageSetup.PaperSize = WdPaperSize.wdPaperA4;
foreach (Microsoft.Office.Interop.Word.InlineShape inline in doc.InlineShapes)
{
if (inline.Height > inline.Width)
{
inline.ScaleWidth = 250;
inline.ScaleHeight = 250;
}
}
doc.PageSetup.TopMargin = 28.29f;
doc.PageSetup.LeftMargin = 28.29f;
doc.PageSetup.RightMargin = 30.29f;
doc.PageSetup.BottomMargin = 28.29f;
application.ActiveDocument.SaveAs(fileName, WdSaveFormat.wdFormatDocument);
doc.Close();
}
}
I thought that with my foreach that problem should not occur. And yes there are more than one pdf in this folder
The line
var doc = application.Documents.Add();
is outside the foreach loop. So you only create a single word document for all your *.pdf files.
Move the above line inside the foreach loop to add a new word document for each *.pdf file.
Is it possible to send to an html a memorystream, like a file?
The idea is not creating a file in the hard drive.
I have created the stream and I can donwload the file no problem, the problem is passing to the variable to send to the aspx page so I can use it to show the file on a particulary div.
Is it possible? without creating a file in the disk.
Best Regards and Thanks
this is the Code i have:
public string ExportMemoryPdf(DataTable dtpdf, String Path)
{
string User = System.Web.HttpContext.Current.User.Identity.Name.ToString();
string Date = DateTime.Now.ToString();
string Year = DateTime.Now.ToString("yyyy");
string Month = DateTime.Now.ToString("MM");
string Day = DateTime.Now.ToString("dd");
string Hour = DateTime.Now.ToString("hh");
string Minutes = DateTime.Now.ToString("mm");
string Seconds = DateTime.Now.ToString("ss");
string FileName = User + Day + Month + Year + Hour + Minutes + Seconds;
//Session["WhereIsIt"].ToString()
//-----------------------Chamada de Classe de Registo de Eventos--------------------------
//string Message = "The User Asked For a PDF File From the Table" + Request.QueryString["Position"] + "With the Filename: " + FileName;
string Message = "The User Asked For a PDF File From the Table With the Filename: " + FileName;
//OneGrid.ExportSettings.IgnorePaging = true;
//OneGrid.Rebind();
//RegisterFile.AddRegistry(User, Message, "Message");
//------------------------------ Variaveis para aceder a Tabela --------------------------
int columncount = dtpdf.Columns.Count;
int rowcount = dtpdf.Rows.Count;
//-------------------------------Iniciaçao de criação do documento -----------------------
Document pdf1 = new Document(PageSize.A4_LANDSCAPE.Rotate());
using (MemoryStream output = new MemoryStream())
{
pdf1.SetMargins(0, 0, 80, 50);
iTextSharp.text.Font font20 = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 10);
//----------------------------------Preparação da Tabela ---------------------------------
PdfPTable table = new PdfPTable(columncount);
//-----------------------------------Criação de Ficheiro ---------------------------------
string path = System.Web.HttpContext.Current.Server.MapPath(Path);
//string path = System.IO.Path.GetTempPath();
//Label1.Text = path.ToString();
//PdfWriter pdfWriter = PdfWriter.GetInstance(pdf1, new FileStream(path + "/" + FileName + ".pdf", FileMode.Create));
PdfWriter pdfWriter = PdfWriter.GetInstance(pdf1, output);
//----------------------------------- Dimensões da Tabela ---------------------------------------
table.WidthPercentage = 90;
//-------------------------------Criação do Header e Footer de cada folha-------------------------
KIOSK.Classes.Header_Footer page = new Classes.Header_Footer();
//-----------------------------------Inserção de conteudos -------------------------------
pdfWriter.PageEvent = page;
pdf1.Open();
//table.AddCell(HttpContext.Current.Request.QueryString["position"].ToString());
for (int z = 0; z < columncount; z++)
{
var sabersenao = dtpdf.Columns[z].ToString();
table.AddCell(new Phrase(sabersenao, font20));
}
for (int u = 0; u < rowcount; u++)
{
int contador = 0;
while (contador < columncount)
{
var CamposCorrigidos = dtpdf.Rows[u].ItemArray[contador].ToString();
StringBuilder ConvPassword = new StringBuilder(CamposCorrigidos);
ConvPassword.Replace("&", string.Empty);
ConvPassword.Replace(" ", string.Empty);
string CamposCorrigidos2 = ConvPassword.ToString();
table.AddCell(new Phrase(CamposCorrigidos2, font20));
contador += 1;
}
}
//----------------------Abertura/Fecho e inserção do componentes necessrios ao pdf---------
pdf1.Add(table);
pdf1.Close();
//System.Web.HttpContext.Current.Response.ClearContent();
//System.Web.HttpContext.Current.Response.ClearHeaders();
//System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
//System.Web.HttpContext.Current.Response.BinaryWrite(output.ToArray());
//System.Web.HttpContext.Current.Response.End();
//System.Web.HttpContext.Current.Response.Flush();
//System.Web.HttpContext.Current.Response.Clear();
//System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
//System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "PdfViewer; filename=" + FileName +".PDF");
////System.Web.HttpContext.Current.Response.AddHeader("content-length", output.Length.ToString());
//System.Web.HttpContext.Current.Response.BinaryWrite(output.ToArray());
//System.Web.HttpContext.Current.Response.End();
//output.Read(pdfByte, 0, (int)pdfByte.Length);
output.Read(pdfByte, 0, (int)pdfByte.Length);
var strBase64 = Convert.ToBase64String(pdfByte);
}
return Convert.ToBase64String(pdfByte);
}
and the error:
Cannot access a closed Stream.
thansk
If you know the content type the memorystream will return, you can read the stream to a variable which handles that type and then process that.
for an example with a String, see How do you get a string from a MemoryStream?. they write a string to a memorystream and then read it back out again.
It's possible, you will have to convert your memorystream to an array of bytes. Then you will have to convert your array of bytes to a Base64 string. And finally you will have to put that base64 string into your img src
An explanation about base64 to image in html.
Take notice that this will work for images. Any other files won't work as since those files need to be downloaded and thus need to have a physical location. Unless you plan on writing a javascript handler for the filetypes you which to show.
Update:
For pdf's you can do the following, however it might not be crossbrowser compatible.
CodeBehind
//string filepath = Server.MapPath("/Temp.pdf");
byte[] pdfByte; //= Helper.GetBytesFromFile(filepath);
using(var stream = ....) {
stream.read(pdfByte,0,(int)pdfByte.length);
var strBase64=Convert.ToBase64String(pdfByte);
HTML
<object data=",<<yourBase64StringHereWithoutthesmallerthenbiggerthenquotes==>>" type="application/pdf" width="800px"></object>
Updated your code:
public string ExportMemoryPdf(DataTable dtpdf, String Path)
{
string User = System.Web.HttpContext.Current.User.Identity.Name.ToString();
string Date = DateTime.Now.ToString();
string Year = DateTime.Now.ToString("yyyy");
string Month = DateTime.Now.ToString("MM");
string Day = DateTime.Now.ToString("dd");
string Hour = DateTime.Now.ToString("hh");
string Minutes = DateTime.Now.ToString("mm");
string Seconds = DateTime.Now.ToString("ss");
string FileName = User + Day + Month + Year + Hour + Minutes + Seconds;
Request.QueryString["Position"] + "With the Filename: " + FileName;
string Message = "The User Asked For a PDF File From the Table With the Filename: " + FileName;
int columncount = dtpdf.Columns.Count;
int rowcount = dtpdf.Rows.Count;
Document pdf1 = new Document(PageSize.A4_LANDSCAPE.Rotate());
pdf1.SetMargins(0, 0, 80, 50);
iTextSharp.text.Font font20 = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 10);
PdfPTable table = new PdfPTable(columncount);
string path = System.Web.HttpContext.Current.Server.MapPath(Path);
table.WidthPercentage = 90;
KIOSK.Classes.Header_Footer page = new Classes.Header_Footer();
for (int z = 0; z < columncount; z++)
{
var sabersenao = dtpdf.Columns[z].ToString();
table.AddCell(new Phrase(sabersenao, font20));
}
for (int u = 0; u < rowcount; u++)
{
int contador = 0;
while (contador < columncount)
{
var CamposCorrigidos = dtpdf.Rows[u].ItemArray[contador].ToString();
StringBuilder ConvPassword = new StringBuilder(CamposCorrigidos);
ConvPassword.Replace("&", string.Empty);
ConvPassword.Replace(" ", string.Empty);
string CamposCorrigidos2 = ConvPassword.ToString();
table.AddCell(new Phrase(CamposCorrigidos2, font20));
contador += 1;
}
}
var base64String = string.Empty;
using (MemoryStream output = new MemoryStream())
{
PdfWriter pdfWriter = PdfWriter.GetInstance(pdf1, output);
pdfWriter.PageEvent = page;
pdf1.Open();
pdf1.Add(table);
pdf1.Close();
bytes = output.ToArray();
var base64String = Convert.ToBase64String(bytes);
}
return base64String;
}
I am currently using lucene.net to search the content of files for keyword search. I am able to get the results correctly but I have a scenario where I need to display the keywords found in a particular file.
There are two different files containing "karthik" and "steven", and if I search for "karthik and steven" I am able to get both the files displayed. If I search only for "karthik" and "steven" separately, only the respective files are getting displayed.
When I search for "karthik and steven" simultaneously I get both the files in the result as I am displaying the filename alone, and now I need to display the particular keyword found in that particular file as a record in the listview.
Public bool StartSearch()
{
bool bResult = false;
Searcher objSearcher = new IndexSearcher(mstrIndexLocation);
Analyzer objAnalyzer = new StandardAnalyzer();
try
{
//Perform Search
DateTime dteStart = DateTime.Now;
Query objQuery = QueryParser.Parse(mstrSearchFor, "contents", objAnalyzer);
Hits objHits = objSearcher.Search(objQuery, objFilter);
DateTime dteEnd = DateTime.Now;
mlngTotalTime = (Date.GetTime(dteEnd) - Date.GetTime(dteStart));
mlngNumHitsFound = objHits.Length();
//GeneratePreviewText(objQuery, mstrSearchFor,objHits);
//Generate results - convert to XML
mstrResultsXML = "";
if (mlngNumHitsFound > 0)
{
mstrResultsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Results>";
//Loop through results
for (int i = 0; i < objHits.Length(); i++)
{
try
{
//Get the next result
Document objDocument = objHits.Doc(i);
//Extract the data
string strPath = objDocument.Get("path");
string strFileName = objDocument.Get("name");
if (strPath == null) { strPath = ""; }
string strLastWrite = objDocument.Get("last_write_time");
if (strLastWrite == null)
strLastWrite = "unavailable";
else
{
strLastWrite = DateField.StringToDate(strLastWrite).ToShortDateString();
}
double dblScore = objHits.Score(i) * 100;
string strScore = String.Format("{0:00.00}", dblScore);
//Add results as an XML row
mstrResultsXML += "<Row>";
//mstrResultsXML += "<Sequence>" + (i + 1).ToString() + "</Sequence>";
mstrResultsXML += "<Path>" + strPath + "</Path>";
mstrResultsXML += "<FileName>" + strFileName + "</FileName>";
//mstrResultsXML += "<Score>" + strScore + "%" + "</Score>";
mstrResultsXML += "</Row>";
}
catch
{
break;
}
}
//Finish off XML
mstrResultsXML += "</Results>";
//Build Dataview (to bind to datagrid
DataSet objDS = new DataSet();
StringReader objSR = new StringReader(mstrResultsXML);
objDS.ReadXml(objSR);
objSR = null;
mobjResultsDataView = new DataView();
mobjResultsDataView = objDS.Tables[0].DefaultView;
}
//Finish up
objSearcher.Close();
bResult = true;
}
catch (Exception e)
{
mstrError = "Exception: " + e.Message;
}
finally
{
objSearcher = null;
objAnalyzer = null;
}
return bResult;
}
Above is the code i am using for search and the xml i am binding to the listview, now i need to tag the particular keywords found in the respective document and display it in the listview as recordsss,simlar to the below listview
No FileName KeyWord(s)Found
1 Test.Doc karthik
2 Test2.Doc steven
i hope u guys undesrtood the question,
This depends on how your documents were indexed. You'll need to extract the original content, pass it through the analyzer to get the indexed tokens, and check which matches the generated query.
Just go with the Highlighter.Net package, part of contrib, which does this and more.