I was wondering if anybody here could help me out as I'm still very new to C#. I have a drive with folders w/in folders that all contain pdffiles. Is there a way to recursively loop through the files and read these files and write the data to a .txt file I'm not sure how to implement this into my Console app--so does anybody have any code that might help?
i tried this prgrm but its throwing errors as "c:\anil not found as file or resource."
class Program
{
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo(@"C:\anil");
FileInfo[] pdfFiles = di.GetFiles("*.pdf", SearchOption.AllDirectories);
foreach (FileInfo pdf in pdfFiles)
{
Console.Write(ReadFile(pdf.FullName));
}
Console.Read();
}
public static string ReadFile(string destfolder)
{
foreach(string file in Directory.Enumeratefiles(destfolder,"*.pdf"))
{
PdfReader pdfreader = new PdfReader(destfolder);
}
string pdfText = string.Empty;
for (int i = 1; i <= pdfreader.NumberOfPages; i++)
{
ITextExtractionStrategy itextextStrat = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
PdfReader reader = new PdfReader(Filename);
String extractText = PdfTextExtractor.GetTextFromPage(reader, i, itextextStrat);
extractText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(extractText)));
pdfText = pdfText + extractText; reader.Close(); } return pdfText;
}
}
}