Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i read the file name and also size ,length as following code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
namespace ClusteringNDD
{

    public partial class Form1 : Form
    {        
        public Form1()
        {
            InitializeComponent();
        }

      
        private void button1_Click(object sender, EventArgs e)
        {
            ArrayList fileStatistics = new ArrayList();
            String datasetPath = @"D:\Data Sets\Enron";
            DirectoryInfo d = new DirectoryInfo(datasetPath);
            FileInfo[] files = d.GetFiles("*.pdf");
            MessageBox.Show(files.Length.ToString());

            foreach (FileInfo file in files)
            {                
                    //create instance of data class
                    fileAtt f = new fileAtt();
                    f.fFullName = file.FullName;
                    f.fName = file.Name;
                    f.FileSize = file.Length;
                    f.fExtension = file.Extension;
                    fileStatistics.Add(f);
                    
                
            }
         

        }
    }
}

and i am also try the foreach loop for each file but some error is there
error like as
" foreach statement cannot operate on variables of type 'System.IO.FileInfo' because 'System.IO.FileInfo' does not contain a public definition for 'GetEnumerator' "
error occur in foreach name code like as
C#
foreach(String data in file)
  {

  }


my requirement is read the content of the file,

pls help me.

thank u
Posted
Comments
PIEBALDconsult 25-Jan-15 10:23am    
That error doesn't seem to match the code.

1 solution

You could read the bytes of each file like this:
C#
foreach (FileInfo fileInfo in files)
{
    byte[] bytes = File.ReadAllBytes(fileInfo.FullName);
}
 
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