[英]Fileupload is not working after downloading file
web-application, c#.NET I have a multiview in Updatepanel and there are three views. web-application, c#.NET 我在 Updatepanel 中有一个多视图,有三个视图。 In third view i am uploading a file and its working.在第三个视图中,我正在上传一个文件及其工作。 Then in first view i need to download file.然后在第一个视图中我需要下载文件。 I achieved it.我做到了。 I want to add one more AsyncFileUpload Control after Download functionality.我想在下载功能之后再添加一个 AsyncFileUpload 控件。 The problem is upload is working but if i first download file and then trying to upload file, its not working(in same view).问题是上传工作但如果我先下载文件然后尝试上传文件,它就不起作用(在同一视图中)。 Its working if i dont download file and upload but not working if i download and then upload file.如果我不下载文件并上传,它可以工作,但如果我下载然后上传文件,它就不能工作。 Code to upload file is as follows.上传文件的代码如下。
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);
}
Here is code to download file.这是下载文件的代码。
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();
}
What may be the problem?可能是什么问题?
I've had this same problem and looking for him these days I have had some problems, but I hope that someone who is in this same inconvenience this tip you can help:我也遇到了同样的问题,这些天在找他时遇到了一些问题,但是我希望遇到同样不便的人可以帮助您:
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);
Consider the value '_self' to run on the same page downloading, and have a new aspx code download.考虑值 '_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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.