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

[Solved] Push file to user from grid

2 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Antoine
Top achievements
Rank 1
Antoine asked on 09 Apr 2008, 04:20 AM
Hi,

Using the grid ItemCommand I'm trying to "push" a file to the client  by doing the following:

 
            // FileInfo object creation 
            System.IO.FileInfo targetFile = new System.IO.FileInfo(filePath); 
 
            // clear the current output content from the buffer 
            HttpContext.Current.Response.Clear(); 
 
            // add the header that specifies the default filename for 
            // the Download/SaveAs dialog 
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name); 
 
            // add the header that specifies the file size, so that the browser 
            // can show the download progress 
            HttpContext.Current.Response.AddHeader("Content-Length", targetFile.Length.ToString()); 
 
            // specify that the response is a stream that cannot be read by the 
            // client and must be downloaded 
            HttpContext.Current.Response.ContentType = GetFileType(targetFile.FullName.ToLower().Substring(targetFile.FullName.Length - 4)); 
 
            // send the file stream to the client 
            HttpContext.Current.Response.WriteFile(targetFile.FullName); 
 
            // stop the execution of this page 
            HttpContext.Current.Response.End(); 

This works fine outside the context of a Radgrid. Im a receiving this error:

Error: [Exception... "'Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. 
Details: Error parsing near '%PDF-1.6 
%ýýýý 
9 0 '.' when calling method: [nsIOnReadyStateChangeHandler::handleEvent]"  nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"  location: "<unknown>"  data: no] 

It seems like it doesn't like that the response headers are modified to push the file to the client with a "save prompt", but this is working everywhere except from a radgrid?

Any clue?

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Apr 2008, 07:00 AM
Hi Oliver,

Writing files in response is not supported in Microsoft ASP.NET AJAX. You can check this link for more info:
http://weblogs.asp.net/leftslipper/comments/2152610.aspx

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Antoine
Top achievements
Rank 1
answered on 09 Apr 2008, 06:11 PM
Hi,

EnableAjax= false; did the trick.

function onRequestStart(ajaxManager, eventArgs) 
  if(eventArgs.EventTarget.indexOf("lnkbtnUpload") != -1) 
  { 
     eventArgs.EnableAjax = false
  } 

Thanks
Tags
Grid
Asked by
Antoine
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Antoine
Top achievements
Rank 1
Share this question
or