Reputation: 69
I want to display only filename with extenstion .pdf, but this code shows me fullpath plus filename.pdf , but I want to display only filename.pdf
Hers is my code and thank you in advance.
string installedPath = Application.StartupPath + "pdfFiles\\" + PatId.ToString() + "\\" + Regnr;
String[] files = Directory.GetFiles(installedPath);
DataTable table = new DataTable();
table.Columns.Add("File name");
for (int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
table.Rows.Add(file);
}
dgvFiles.DataSource = table;
Upvotes: 0
Views: 134
Reputation: 114
Maybe not the most professional solution, but a string.Split should do the work
for (int i = 0; i < files.Length; i++)
{
string[] temp = files[i].Split('\\');
string fileName = temp.Last();
FileInfo file = new FileInfo(fileName);
table.Rows.Add(file);
}
Upvotes: 1