web-application, c#.NET I have a multiview in Updatepanel and there are three views. In third view i am uploading a file and i开发者_如何学运维ts working. Then in first view i need to download file. I achieved it. I want to add one more AsyncFileUpload Control after Download functionality. 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.
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();
精彩评论