Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
int index = Convert.ToInt32(e.CommandArgument);
                   string path = "select FileData,extension,upload_filename,contentType from ImprestExpenseDetails where BillNo='" + index + "'";
                   DataSet ds = new DataSet();
                   ds = objcBLL.GetQueryResult(path, "ImageView");
                   if (ds.Tables["ImageView"].Rows.Count > 0)
                   {
                       Byte[] bytes = (Byte[])ds.Tables["ImageView"].Rows[0]["FileData"];
                       string extension = (string)ds.Tables["ImageView"].Rows[0]["extension"];
                       string filename = (string)ds.Tables["ImageView"].Rows[0]["upload_filename"];
                       string contenttype = (string)ds.Tables["ImageView"].Rows[0]["contentType"];

                       if (extension == ".pdf")
                       {
                           string fpath = Server.MapPath("~/" + filename);
                           Response.Buffer = true;
                           Response.Charset = "";
                           Response.Cache.SetCacheability(HttpCacheability.NoCache);
                           Response.ContentType = contenttype;
                           Response.AddHeader("content-disposition", "attachment;filename=" + filename);
                           Response.BinaryWrite(bytes);
                           Response.Flush();
                           Response.End();
                       }


                       if (extension == ".jpg")
                       {

                       }
                   }


What I have tried:

I got the error on Response.End()
i use HttpContext.Current.ApplicationInstance.CompleteRequest(); inplace of Response.End();
after using this error is resolved but file is not downloaded.
Please help
Posted
Updated 29-Mar-16 23:59pm

1 solution

If you get an error message you don't understand, Google it:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call - Google Search[^]
As you can see, you aren't the first to have this problem.
Start looking at some of the links, and you will find this: asp.net - Response.End() throwing an Error - Stack Overflow[^] which is probably the same problem (and a solution).
Response.End is designed to terminate a page - so if you have an synchronous download going at the same time, then yes, it will probably terminate it.
 
Share this answer
 
Comments
prakash00060 31-Mar-16 7:28am    
I have tried but not get anything please give the actual resolution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900