C# 为什么输入文件正在缓存旧上传的图像?

C# 为什么输入文件正在缓存旧上传的图像?,c#,asp.net,webforms,C#,Asp.net,Webforms,我有引导模式弹出窗口,允许用户选择要上传的图像,因此当用户选择图像时,我有javascript功能,可以添加包含文件名的新,然后用户单击保存将图像保存到数据库中,除了输入文件正在缓存旧图像并使用新选择的图像再次上载它们之外,其他一切都正常工作 <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="functionalUpdatePanel"> <ContentTemplate&g

我有
引导模式
弹出窗口,允许用户选择要上传的图像,因此当用户选择图像时,我有
javascript
功能,可以添加包含文件名的新
,然后用户单击保存将图像保存到数据库中,除了输入文件正在缓存旧图像并使用新选择的图像再次上载它们之外,其他一切都正常工作

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="functionalUpdatePanel">
                <ContentTemplate>
    <button title="إضافة مرفق" data-toggle="modal" class="uploadAttach" data-target="#myModal" ></button>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- 
                labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria- 
                hidden="true"> </button>
                <h4 class="modal-title" id="myModalLabel">إضافة مرفق</h4>
                </div>
                <div class="modal-body">
                <asp:Label ID="lblMessage" runat="server" ForeColor="Green" />                  

                    <h5 style="margin-right:45%;font-weight:bold;font- 
                      size:1.2em">اختر المرفق</h5>             

                    <div class="uploadBtnDiv">


                        <input 
             style="cursor:pointer;opacity:0;width:100%;height:100%"  
                    title="اختيار مرفق" type="file" id="myFile" name="myFile"   
                   multiple="multiple" />

                    </div>      

                    <br />
                    <br />

                </div>
                <div class="modal-footer">

                 <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                                                <ContentTemplate>
                                                    <asp:Button style="width:100% 
                    !important;" Text="حفظ" title="إرسال المرفق" CssClass="btn 
                    btn-success" runat="server" ID="btnUpload" 
                     OnClick="btnUploadClick"      />
                                                 </ContentTemplate>
                                                <Triggers>
                                                    <asp:PostBackTrigger 
                     ControlID="btnUpload" />
                                                </Triggers>
                                            </asp:UpdatePanel>
                </div>
            </div> 
            </div> 
        </div> 
             </ContentTemplate>
                <Triggers>


                </Triggers>
            </asp:UpdatePanel>

إضافة مرفق
اختر المرفق             


这是我的java脚本函数

  $(document).on('change', '#myFile:visible', function() {

    var files = $(this)[0].files;
    var newLine;

    for (var i = 0; i < files.length; i++) {

        newLine = "<div class='attach-line'>" +
                    "<div class='attach-name'>" +

            files[i].name.slice(0,25)+'...' +

            "<i    class='icon-trash remove attach-delete'></i>" +

                    "</div>" +
                      "<br/>"+   
                  "</div>";

        $("#myModal .modal-body").append(newLine);

        // Clone the file selector, assign the name, hide and append it
        $(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));

      }
      $(".remove").click(function(){
            $(this).parent(".attach-name").remove();
          });
});
$(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));
$(document).on('change','myFile:visible',function(){
var files=$(this)[0]。文件;
var新线;
对于(var i=0;i”+
"";
$(“#myModal.modal body”).append(换行符);
//克隆文件选择器,指定名称,隐藏并附加它
$(this.clone().hide().attr('name','myFile[]).insertAfter($(this));
}
$(“.remove”)。单击(函数(){
$(this.parent(“.attach name”).remove();
});
});
贝娄是背后的代码

 protected void btnUploadClick(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt.Columns.Add("AppId", typeof(int));
            dt.Columns.Add("Bytes", typeof(byte[]));
            dt.Columns.Add("ImgNames", typeof(string));
            dt.Columns.Add("ImgType", typeof(string));
            dt.Columns.Add("DedicatedMemberId", typeof(int));


            for (int i = 0; i < Request.Files.Count; i++)
            {
                if (Request.Files[i] != null && Request.Files[i].ContentLength > 0)
                {

                    string fType = Request.Files[i].ContentType.Split('/')[1];
                    string fName = Path.GetFileName(Request.Files[i].FileName);
                    byte[] bytes = new BinaryReader(Request.Files[i].InputStream).ReadBytes(Request.Files[i].ContentLength);
                    dt.Rows.Add(Convert.ToInt32(hfAppId.Value), bytes, fName,
                        fType, Convert.ToInt32(ViewState["memberId"]));
                }
            }
            string outputStr = AppsOperations.UpdateAttach("إرفاق صورة جديدة", "الطلبات ", dt, User.Identity.Name);

            if (outputStr == "s")
            {

                string redirectStr = "AuditApp.aspx?seq=" + hfAttSeq.Value + "&&AppType=" + hfAppType.Value + "&&id=" + hfAppId.Value;
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('تم تحميل المرفق بنجاح');window.location='" + redirectStr + "';", true);

            }
            else if (outputStr == "f")

            {

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + "تعذر تحميل المرفق" + "')", true);

            }

        }
protectedvoid btnUploadClick(对象发送方,事件参数e)
{
DataTable dt=新的DataTable();
添加(“AppId”,typeof(int));
添加(“字节”,typeof(byte[]);
添加(“ImgNames”,typeof(string));
添加(“ImgType”,typeof(string));
添加(“专用成员”,类型(int));
对于(int i=0;i0)
{
字符串fType=Request.Files[i].ContentType.Split('/')[1];
字符串fName=Path.GetFileName(Request.Files[i].FileName);
byte[]bytes=新的二进制读取器(Request.Files[i].InputStream).ReadBytes(Request.Files[i].ContentLength);
Add(Convert.ToInt32(hfAppId.Value)、bytes、fName、,
fType,Convert.ToInt32(ViewState[“memberId”]);
}
}
字符串输出str=AppsOperations.updateAttch(“إ㶈㶈㶤㶤㶧㶡”、“㶊㶕㶈ت”、dt、User.Identity.Name);
如果(outputStr==“s”)
{
string redirectStr=“AuditApp.aspx?seq=“+hfAttSeq.Value+”&&AppType=“+hfAppType.Value+”&&id=“+hfAppId.Value;
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“alertMessage”,“alert”(“this,this.GetType()”);window.location=“+redirectStr+”,true);
}
else if(outputStr==“f”)
{
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“alertMessage”,“alert”(“+”或“+”)),“true);
}
}

我能够找到答案,实际上我在另一个页面中使用了相同的代码来缓存图像以供使用,因此我从java脚本函数中删除了下面这一行

  $(document).on('change', '#myFile:visible', function() {

    var files = $(this)[0].files;
    var newLine;

    for (var i = 0; i < files.length; i++) {

        newLine = "<div class='attach-line'>" +
                    "<div class='attach-name'>" +

            files[i].name.slice(0,25)+'...' +

            "<i    class='icon-trash remove attach-delete'></i>" +

                    "</div>" +
                      "<br/>"+   
                  "</div>";

        $("#myModal .modal-body").append(newLine);

        // Clone the file selector, assign the name, hide and append it
        $(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));

      }
      $(".remove").click(function(){
            $(this).parent(".attach-name").remove();
          });
});
$(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));

如果你可以共享一个,那就太棒了。我共享前端、java脚本和后端。除了输入文件正在缓存旧图像并使用新选择的图像再次上载它们之外,其他东西都在工作-你的意思是用户添加并上载文件1,然后添加并上传文件2-不刷新页面-并且再次上传文件1?您认为这可能是因为该文件仍在
myFile
中吗?也许您应该在上传后删除它?是的,用户选择一个文件,单击“上载”时,它将上载所选文件并添加旧文件SO。。上传文件后,您不应该将其从列表中删除吗?