Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET清除HttpContext.Current.Request.Files_Asp.net_File_Upload_Httpcontext - Fatal编程技术网

ASP.NET清除HttpContext.Current.Request.Files

ASP.NET清除HttpContext.Current.Request.Files,asp.net,file,upload,httpcontext,Asp.net,File,Upload,Httpcontext,如何清除HttpContext.Current.Request.Files列表 回发后,仍包含文件 protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) this.SaveImages(); } private Boolean SaveImages() { //loop through the files uploaded

如何清除HttpContext.Current.Request.Files列表

回发后,仍包含文件

protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack)
            this.SaveImages();
}

private Boolean SaveImages()
    {
        //loop through the files uploaded
        HttpFileCollection _files = HttpContext.Current.Request.Files;
        //Message to the user
        StringBuilder _message = new StringBuilder("Files Uploaded:<br>");
        try
        {
            for (Int32 _iFile = 0; _iFile < _files.Count; _iFile++)
            {
                if (!string.IsNullOrEmpty(_files[_iFile].FileName))
                {
                    // Check to make sure the uploaded file is a jpg or gif
                    HttpPostedFile _postedFile = _files[_iFile];
                    string _fileName = Path.GetFileName(_postedFile.FileName);
                    string _fileExtension = Path.GetExtension(_fileName);

                    //Save File to the proper directory
                    _postedFile.SaveAs(HttpContext.Current.Request.MapPath("files/") + _fileName);
                    _message.Append(_fileName + "<BR>");
                }
            }
            lblFiles.Text = _message.ToString();
            return true;
        }
        catch (Exception Ex)
        {
            lblFiles.Text = Ex.Message;
            //Refill images in control????
            return false;
        }
        finally
        {
            //Clear HttpContext.Current.Request.Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }
    }

显示一些代码以及在哪个事件中执行此操作??是否有任何特殊原因,即您试图在页面上保存图像?加载事件?我觉得这很奇怪!我只是在听一个教程。有没有更好的方法可以做到这一点?是否有一些特殊的原因使您需要尽早删除这些文件?无论如何,当请求已被处理时,它们将被删除。。。