Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have develop winform app for accessing pdf properties like filename and full path of

file,size,extension,content of pdf file.alredy i am accessing path of file and content

of pdf file then i want remaing properties like filename,size,extension


Important:File class is useful for fileinfoarray but i am not using fileinfo array i

am using string array only.pls don't tell to use File class.it is not useful for filname,size,extensions.File class have no method for access extension,filename,size.if any

approaches will be there tell me.

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 System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Windows.Forms;
using pdf_app.Lib;

namespace pdf_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)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.CheckFileExists = true;
            openFileDialog.AddExtension = true;
            openFileDialog.Multiselect = true;
            openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
            DialogResult result = openFileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string[] files = openFileDialog.FileNames;
            }
            foreach (string access in openFileDialog.FileNames)
            {
                fileatt f = new fileatt();
                f.fFullName = access;
                f.fContent = ExtractTextFromPdf(access);
            }
        }

fileatt class like :
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pdf_app.Lib
{
    class fileatt
    {
        public long FileSize { get; set; }
        public string fName { get; set; }
        public string fFullName { get; set; }
        public string fExtension { get; set; }
        public string fContent { get; set; }
    }
}


i want remaing properties like filename,size,extension

pls help me.
Posted
Updated 9-Feb-15 0:36am
v2
Comments
Deepu S Nair 9-Feb-15 6:39am    
Similar to your last question.
Krishna Veni 9-Feb-15 6:48am    
how can u access remaing properties like filename,size,extension
Deepu S Nair 9-Feb-15 7:00am    
this looks similar to your previous question.
Krishna Veni 9-Feb-15 7:03am    
that is not useful for my developed code.if any other approaches tell me.
Deepu S Nair 9-Feb-15 7:13am    
You already asked this question before then why are you reposting?

1 solution

The question was not answered correctly on your previous post. I believe the poster should have directed you to the FileInfo class[^]
 
Share this answer
 
Comments
Deepu S Nair 9-Feb-15 7:48am    
good one.

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