我检查了这个问题的几种解决方案,当你第一次上传 a.jpg 时没问题,但当你再次上传 a.jpg 时,它就不起作用了。再次上传 a.jpg 的唯一方法是上传 b.jpg。
我的代码看起来像这样
<p>Select file to upload:</p>
<asp:FileUpload ID="FileUploader" runat="server" Width="1000px" />
<br />
服务器代码如下所示
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
我读过将 fileUploader 放在更新面板上的解决方案。我还尝试在上传文件后重命名该文件。这有效,但它破坏了我的逻辑
慕田峪7331174
相关分类