Condense file path

Niladri.Biswas
Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 1387
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "sql files (*.sql)|*.sql";
dialog.InitialDirectory = "C:";
dialog.Title = "Select a .sql file";

if (dialog.ShowDialog() == DialogResult.OK)
{
var fileName = dialog.FileName;

if (fileName.Length > 100)
{
lblFolderChoosen.Text = Path.GetPathRoot(fileName) + ".." + "\\" + dialog.SafeFileName;
}
else
{
lblFolderChoosen.Text = fileName;
}
}

Comments or Responses

Login to post response