亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

asp.net fileUpload不會上傳同一文件兩次

asp.net fileUpload不會上傳同一文件兩次

C#
莫回無 2023-07-09 17:47:58
我檢查了這個問題的幾種解決方案,當你第一次上傳 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 放在更新面板上的解決方案。我還嘗試在上傳文件后重命名該文件。這有效,但它破壞了我的邏輯
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

我重新保存了文件,然后服務器認為它不處理相同的文件


  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));


            string day = DateTime.Now.ToString("ss_mm_hh_dd_MM_yyyy");


            FileUploader.SaveAs(Server.MapPath(path));


            //Function to insert values in excel sheet to database

            InsertIntoDatabase(filePath)


             //Resave file to keep track of uploaded files

            File.Copy(filePath, day + filePath);

            File.Delete(filePath);

        }

        catch (Exception Ex)

        {


        }//End try


    }//End FileUpload 


查看完整回答
反對 回復 2023-07-09
  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號