下载文件后,文件上传不工作

本文关键字:文件 工作 下载 | 更新日期: 2023-09-27 18:05:43

web-application, c#。网我在Updatepanel中有一个多视图,有三个视图。在第三视图中,我正在上传一个文件和它的工作。然后在第一个视图,我需要下载文件。我做到了。我想在下载功能后再添加一个AsyncFileUpload控件。问题是上传工作,但如果我先下载文件,然后试图上传文件,它不工作(在同一视图)。它的工作,如果我不下载文件和上传,但不工作,如果我下载,然后上传文件。上传文件的代码如下:

string filename = Path.GetFileName(AsyncFileUpload1.FileName);
                string ext = Path.GetExtension(filename);
                if (ext == ".exe" || ext == ".EXE" || ext == ".dll" || ext == ".DLL" || ext == ".config" || ext == ".CONFIG" || ext == ".com" || ext == ".COM")
                {
                    fName = null;
                    lblStatus.Text = "You cant upload " + ext.ToString() + " Files";
                }
                else
                {
                    string newfilename =  e.filename;
                    string strPath = MapPath("../MsgAttach/") + Path.GetFileName(newfilename);
                    AsyncFileUpload1.SaveAs(strPath);
                }

这是下载文件的代码

string filename = hd_file.Value.ToString();
        string filepath = MapPath("../MsgAttach/" + filename);
        if (File.Exists(filepath))
        {
            byte[] buffer;
            using (FileStream fileStream = new FileStream(filepath, FileMode.Open))
            {
                int fileSize = (int)fileStream.Length;
                buffer = new byte[fileSize];
                // Read file into buffer
                fileStream.Read(buffer, 0, (int)fileSize);
            }
            Response.Clear();
            Response.Buffer = true;
            Response.BufferOutput = true;
            Response.ContentType = "application/x-download";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
            Response.CacheControl = "public";
            // writes buffer to OutputStream
            Response.OutputStream.Write(buffer, 0, buffer.Length);
            Response.End();
        }

可能是什么问题?

下载文件后,文件上传不工作

我也遇到过同样的问题,这些天我也遇到了一些问题,但是我希望在这个提示中遇到同样不便的人可以帮助:

linkMass string = <your new page aspx>;
             ScriptManager.RegisterStartupScript (this.Page, this.GetType (), "script1", "window.open ('" + linkMass +' ',' _self '' directories = no, toolbar = no, scrollbars = no, resizable = no, top = 10, left = 10, width = 200, height = 100 '); ", true);

考虑值'_self'运行在同一个页面下载,并有一个新的aspx代码下载。

Response.Clear();
            Response.Buffer = true;
            Response.BufferOutput = true;
            Response.ContentType = "application/x-download";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
            Response.CacheControl = "public";
            // writes buffer to OutputStream
            Response.OutputStream.Write(buffer, 0, buffer.Length);
            Response.End();
相关文章: