"Display File Name path in Combobox using C#.Net"
addParentdirectoryFile Method
addParentdirectoryFile Method
private void addParentdirectoryFile(string sourcePath)
{
string[] fileNames = Directory.GetFiles(sourcePath);
foreach (string str in fileNames)
{
comboBox1.Items.Add(str);
}
}
addChildDirectFiles Method
{
string[] fileNames = Directory.GetFiles(sourcePath);
foreach (string str in fileNames)
{
comboBox1.Items.Add(str);
}
}
private void addChildDirectFiles(string sourcePath)
{
foreach (string subFolders in Directory.GetDirectories(sourcePath,"*",SearchOption.AllDirectories))
{
string[] subFolderfileNames = Directory.GetFiles(subFolders);
foreach (string fname in subFolderfileNames)
{
comboBox1.Items.Add(fname);
}
}
}
Call this method where you want:
{
foreach (string subFolders in Directory.GetDirectories(sourcePath,"*",SearchOption.AllDirectories))
{
string[] subFolderfileNames = Directory.GetFiles(subFolders);
foreach (string fname in subFolderfileNames)
{
comboBox1.Items.Add(fname);
}
}
}
addParentdirectoryFile();
addChildDirectFiles();
addChildDirectFiles(