I have checked several solutions to this problem where when you upload a.jpg the first time is fine but when you upload a.jpg again, it won't work. The only way you could upload a.jpg again is when you upload b.jpg.
My code looks like this
<p>Select file to upload:</p>
<asp:FileUpload ID="FileUploader" runat="server" Width="1000px" />
<br />
And the server code looks like this
protected void FileUploadButton_Click(object sender, EventArgs e)
{
try
{
//File upload logic. Returns path of uploaded file
string filePath = Server.MapPath("~/Files/") + Path.GetFileName(FileUploader.PostedFile.FileName);
//File save to server. Saves file name as uploaded by user to folder, "Files" on the server
string path = System.IO.Path.Combine("~/Files/",Path.GetFileName(FileUploader.PostedFile.FileName));
FileUploader.SaveAs(Server.MapPath(path));
//Function to insert values in excel sheet to database
InsertIntoDatabase(filePath)
}
catch (Exception Ex)
{
}//End try
}//End FileUpload
I have read solutions where you put the fileUploader on an update panel. I also tried renaming the file after it is uploaded. That worked but it breaks my logic down the line