I've got an application that reads all the files and sub folders within the built assembly directory and display it using a datagridview. But I when try to run the application in my network drive to try scanning the files within that drive, it gives out the exception "Access to path 'F:/System File Volume' is denied" and then the application will stop running. Any idea on how to get pass the System File Volume, and still display those files which can be access. Here is my code if needed :
private void Form1_Load(object sender, EventArgs e)
{
count = 0;
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer1_Tick);
timer.Start();
s1 = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.*", SearchOption.AllDirectories);
for (int i = 0; i <= s1.Length - 1; i++)
{
if (i == 0)
{
dt.Columns.Add("File_Name");
dt.Columns.Add("File_Type");
dt.Columns.Add("File_Size");
dt.Columns.Add("Create_Date");
}
try
{
FileInfo info = new FileInfo(s1[i]);
FileSystemInfo sysInfo = new FileInfo(s1[i]);
dr = dt.NewRow();
dr["File_Name"] = sysInfo.Name;
dr["File_Type"] = sysInfo.Extension;
dr["File_Size"] = (info.Length / 1024).ToString();
dr["Create_Date"] = sysInfo.CreationTime.Date.ToString("dd/MM/yyyy");
dt.Rows.Add(dr);
if ((info.Length / 1024) > 1500000)
{
MessageBox.Show("" + sysInfo.Name + " had reach its size limit.");
}
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
continue;
}
}
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
count++;
if (count == 60)
{
count = 0;
timer.Stop();
Application.Restart();
}
}
public string secondsToTime(int seconds)
{
int minutes = 0;
int hours = 0;
while (seconds >= 60)
{
minutes += 1;
seconds -= 60;
}
while (minutes >= 60)
{
hours += 1;
minutes -= 60;
}
string strHours = hours.ToString();
string strMinutes = minutes.ToString();
string strSeconds = seconds.ToString();
if (strHours.Length < 2)
strHours = "0" + strHours;
if (strMinutes.Length < 2)
strMinutes = "0" + strMinutes;
if (strSeconds.Length < 2)
strSeconds = "0" + strSeconds;
return strHours + ":" + strMinutes + ":" + strSeconds;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
BindingSource bind = new BindingSource();
bind.DataSource = dt;
bind.Filter = string.Format("File_Name like '%{0}%'", textBox1.Text.Trim());
}