Updated:
I used .net 4.0 for coding, I want to find a pdf file with an specific path(ViewState["MediaFile"]) and transfer it to local system.
This is my code for File Transfer :
//---server path ---
String sFilePath = Server.MapPath("~/" + ViewState["MediaFile"].ToString());
String sFileName= System.IO.Path.GetFileName(sFilePath);
String RelativePath =sFilePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
String Header = "Attachment; Filename=" + sFileName;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
System.IO.FileInfo Dfile = new System.IO.FileInfo(RelativePath);
HttpContext.Current.Response.End();
but after running, there 's an error:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
when I put HttpContext.Current.ApplicationInstance.CompleteRequest() instead of HttpContext.Current.Response.End() it's not error but do NOTHING!!! I mean a download panel is not shown.
Note: I test this code on another page,it works. just want to say is it possible because of any code in my form? I use Ajax UpdatePanel and disable right click on the form.