Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i have develop winform app for pdf files detailes and bind to the gridview

i have read the content of pdf file and pdffullname(path of filename) but i want to how

to read filename(not path of file),size,extension of files and problem the binding the

gridview .i had binded the fullname of file using list collection to the gridview but

gridview shows the length attribute only .finally i want pdfdetailes(filename,size,length) and

slove the binding problem.

my developed code:

C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using form_app.Lib;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace form_app
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
          
        }
        public static string ExtractTextFromPdf(string filename)
        {
            using (PdfReader r = new PdfReader(filename))
            {
                StringBuilder text = new StringBuilder();

                for (int i = 1; i <= r.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(r, i));
                }
                return text.ToString();
            };
        }
        private void button1_Click(object sender, EventArgs e)
        {
              List<string> filelist = new List<string>();
            
            string pathName = @"D:\Data Sets\Enron";

            string[] pdfFileNames = Directory.GetFiles(pathName, "*.pdf");
            MessageBox.Show(pdfFileNames.Length.ToString());

            foreach (string pdfFileName in pdfFileNames)
            {
              
                fileproperties fi = new fileproperties ();
                fi.fullname = pdfFileName;
                fi.content = ExtractTextFromPdf(pdfFileName);
                filelist.Add(fi.fullname);
            }
         
            dataGridView1.DataSource = filelist;
        } 

        }
    }


fileproperties.cs:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace form_app.Lib
{
    class fileproperties
    {
        public long filesize { get; set; }
        public string filename { get; set; }
        public string fullname { get; set; }
        public string extension { get; set; }
        public string content { get; set; }
    }
}


pls help me.
Posted
Updated 8-Feb-15 0:01am
v2
Comments
Richard MacCutchan 8-Feb-15 6:40am    
Your filelist contains only the filename from the fileproperties class, so that is what is bound to the grid. You need to bind the fileproperties objects and their properties.
Krishna Veni 8-Feb-15 7:09am    
ya i bind the file properties but i want pdf file properties it is not same to the general text file.provide link not usefull

1 solution

Maybe this link can help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900