This is a migrated thread and some comments may be shown as answers.

not on top of call stack ?!

2 Answers 80 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 2
Mario asked on 12 Aug 2009, 03:38 PM
Hy i have a rad grid, which im using a RadMenu as a context menu with it. All works fine.

The Radmenu Command calls the method "OpenFile(int id)" in the code behind file to as u correctly guess should opens a already on the server stored file in a file stream to the client.

Heres the method:

private void OpenFile(int id) 
        { 
            try 
            { 
                Document doc = BLDocument.GetDocument(id); 
 
                if (File.Exists(doc.Metainformation.filepath)) 
                { 
                    // Create New instance of FileInfo class to get the properties of the file being downloaded 
                    FileInfo file = new FileInfo(doc.Metainformation.filepath); 
  
                    // Clear the content of the response 
                    Response.ClearContent(); 
 
                    // LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header 
                    Response.AddHeader("Content-Disposition""attachment; filename=" + file.Name); 
 
                    // Add the file size into the response header 
                    Response.AddHeader("Content-Length", file.Length.ToString()); 
 
                    // Set the ContentType 
                    Response.ContentType = ReturnExtension(file.Extension.ToLower()); 
 
                    // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead) 
                    Response.TransmitFile(file.FullName); 
 
                    // End the response 
                    Response.End(); 
                } 
            } 
            catch (Exception ex) 
            { 
 
            } 
        } 

After i reach the Reespnse.End(); line i get following exception:

((System.Threading.ThreadAbortException)(ex)):


{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

Is there any propertie i have to set to be able to give my user the file / filestream ?
Or what can i do to make it work properly?

thx mario

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 Aug 2009, 04:00 PM
Hi Mario,

Response.End() always triggers the ThreadAbortException. You can check this page for additional info.

All the best,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mario
Top achievements
Rank 2
answered on 13 Aug 2009, 10:52 AM
I had enabled (added) the Context Menu (im using with my radgrid) with Ajax which runs a thread and so it has a problem ending the thread.

When i dont add the calling button control to ajaxmanager it works.

PS.:

Also read that some people have problems debugging it with their Visual Studio, when they Resonse.End in a try catch block, but thats only a problem with a wrongly configured Visual Studio.

thx Mario

MARK THIS AS ANSWER ^^
Tags
Menu
Asked by
Mario
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Mario
Top achievements
Rank 2
Share this question
or