If file exist in the folder and in the database, how can I add extension at the end of the filename?
For example, if a filename like this exists:
JOHN_DENVER_SMITH.pdf
the code should rename the 2nd record to JOHN_DENVER_SMITH_(1).pdf
.
Here's my code:
FileInfo fileInfo = new FileInfo(oldPath);
if (fileInfo.Exists)
{
try
{
if (!Directory.Exists(newPath))
{
Directory.CreateDirectory(newPath);
}
fileInfo.MoveTo(string.Format("{0}{1}{2}", newPath, firstname.Text + "_" + midlename.Text + "_" + lastname.Text, fileInfo.Extension));
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
}
}