Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have develop winform app for reading filename,path of file,extension,filesize,content

of pdf file.all these properties are working well except content of pdf file.content of

pdf file format is bytearray. i want convert bytearray to fileinfo array.

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

        private void button1_Click(object sender, EventArgs e)
        {
           ArrayList files = new ArrayList();
            string path = @"D:\Data Sets\Enron";
            DirectoryInfo d = new DirectoryInfo(path);
            FileInfo[] pdffilenames = d.GetFiles("*.pdf");
            foreach(FileInfo pdffilename in pdffilenames)
            {
                fileatt f = new fileatt();
                f.fFullName = pdffilename.FullName;
                f.fName = pdffilename.Name;
                f.FileSize = pdffilename.Length;
                f.fExtension = pdffilename.Extension;
                byte[] bytes = File.ReadAllBytes(pdffilename.FullName);
                           
            }
            MessageBox.Show("successfully");
        }

       
    }
}


Fileatt.cs
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; }
    }
}

please help me.
Posted

1 solution

OK, so why then is your foreach loop creating a fileatt object, setting its properties and then throwing it away? You're not doing anything with that object you just created.

Also, your fileatt.fContent property is typed as a string, which the byte[] you get when you ReadAllBytes will not convert to with any meaning. You have to change that string to byte[] in order for it to make any sense.
 
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