In my application Im saving multiple files(image,pdf,txt) to a folder. Suppose I have an image with name "image1", if this image already exists in the folder and if another user tries to add another image with the same name "image1" then, it should give message to change the File name.
I had used below code:
string filePath = DamRep_FileUpload.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string contenttype = String.Empty;
if (contenttype != String.Empty)
{
if (File.Exists("~/FTP/File/"))
{
LMsg.Visible = true;
LMsg.Text = "File name already exist. Change the File name if u want to save this file";
}
else
{
string fileName = Path.GetFileName(DamRep_FileUpload.PostedFile.FileName);
DamRep_FileUpload.PostedFile.SaveAs(Server.MapPath("~/FTP/File/") + fileName);
Response.Redirect(Request.Url.AbsoluteUri);
}
}
but its not working.
Please suggest some help as per my requirement.