I am having a problem that I have been trying for a while to figure out.
I have a RadGrid that has a GridButtonColumn connected to c# function that I use to pull path and file info from a database and open the file from a file server.
If I use this on an ASPX page by itself, it works like a charm.
If I include this same RadGrid control and code in another RadGrid Edit Form, the function runs and appears to complete successfully.
I debug it and it runs and completes just the same, the file.FullName is right, just like when it tuns in the other form, but the Response.Flush does not open the file.
When the Response.Flush runs in the debugger, I see the focus go back to the browser for a flash and back to the debugger, but no file open dialog or anything else.
I bet someone out there knows what is going on. Help!
Thanks!
Here is my ItemCommand call:
protected
void
OpenAttchTable_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"Open"
)
// CommandName of LinkButton
{
GridDataItem item = e.Item
as
GridDataItem;
String filePath = @item[
"filePath"
].Text;
String fileName = item[
"fileName"
].Text;
String FullFilePath = @filePath + fileName;
FileInfo file =
new
FileInfo(FullFilePath);
String fileExt = file.Extension;
switch
(fileExt)
{
case
".csv"
:
Response.ContentType =
"text/csv"
;
break
;
case
".doc"
:
Response.ContentType =
"application/msword"
;
break
;
case
".docx"
:
Response.ContentType =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
;
break
;
case
".gif"
:
Response.ContentType =
"image/gif"
;
break
;
case
".jpeg"
:
Response.ContentType =
"image/jpeg"
;
break
;
case
".jpg"
:
Response.ContentType =
"image/jpeg"
;
break
;
case
".pdf"
:
Response.ContentType =
"application/pdf"
;
break
;
case
".png"
:
Response.ContentType =
"image/png"
;
break
;
case
".ppt"
:
Response.ContentType =
"application/vnd.ms-powerpoint"
;
break
;
case
".pptx"
:
Response.ContentType =
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
;
break
;
case
".txt"
:
Response.ContentType =
"text/plain"
;
break
;
case
".xls"
:
Response.ContentType =
"application/vnd.ms-excel"
;
break
;
case
".xlsx"
:
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;
break
;
default
:
Response.ContentType =
"application/octet-stream"
;
break
;
}
if
(file.Exists)
{
if
(file.Length > 30000000)
{
String Message =
"The file exceeds the Maximum length of 30 Megabytess."
;
ClientScript.RegisterStartupScript(
this
.GetType(),
"Warnings"
,
"alert('"
+ Message +
"');"
,
true
);
}
else
{
Response.AddHeader(
"Content-Disposition"
,
"attachment; filename="
+ file.Name);
Response.AddHeader(
"Content-Length"
, file.Length.ToString());
Response.ClearContent();
Response.AddHeader(
"Content-Disposition"
,
"attachment; filename="
+ file.Name);
Response.AddHeader(
"Content-Length"
, file.Length.ToString());
Response.TransmitFile(file.FullName);
Response.Flush();
Response.End();
}
}
}
}
Here is my ASPX Markup:<
asp:Panel
runat
=
"server"
Visible
=
"true"
>
<
div
class
=
"row"
>
<
div
class
=
"col-sm-12"
>
<
div
id
=
"OpenAttchGridDiv"
runat
=
"server"
Visible
=
"true"
>
<
telerik:RadGrid
ID
=
"OpenAttchTable"
EnableViewState
=
"true"
runat
=
"server"
AutoGenerateColumns
=
"false"
GridLines
=
"Both"
AllowPaging
=
"false"
PageSize
=
"10"
AllowFilteringByColumn
=
"False"
AllowSorting
=
"true"
ShowStatusBar
=
"false"
MasterTableView-CommandItemDisplay
=
"None"
AllowAutomaticDeletes
=
"true"
AllowAutomaticInserts
=
"false"
AllowAutomaticUpdates
=
"false"
MasterTableView-EditMode
=
"EditForms"
Skin
=
"Metro"
OnNeedDataSource
=
"OpenAttchTable_NeedDataSource"
OnItemCommand
=
"OpenAttchTable_ItemCommand"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
ClientSettings
>
<
ClientEvents
OnPopUpShowing
=
"PopUpShowing"
/>
</
ClientSettings
>
<
MasterTableView
Width
=
"100%"
UseAllDataFields
=
"true"
ShowHeader
=
"true"
InsertItemDisplay
=
"Top"
CommandItemDisplay
=
"None"
InsertItemPageIndexAction
=
"ShowItemOnFirstPage"
>
<
EditFormSettings
>
<
PopUpSettings
Modal
=
"true"
ZIndex
=
"10"
ScrollBars
=
"Vertical"
/>
</
EditFormSettings
>
<
Columns
>
<%--<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandcolumn"
></
telerik:GridEditCommandColumn
>--%>
<
telerik:GridBoundColumn
UniqueName
=
"helpDeskTicketID"
DataField
=
"helpDeskTicketID"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"helpDeskAttachmentID"
DataField
=
"helpDeskAttachmentID"
Display
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"attachmentTypeID"
DataField
=
"attachmentTypeID"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"attachmentTypeDesc"
DataField
=
"attachmentTypeDesc"
Visible
=
"true"
HeaderText
=
"Attachment Type"
AllowFiltering
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"attachmentVersionID"
DataField
=
"attachmentVersionID"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"attachmentVersionDesc"
DataField
=
"attachmentVersionDesc"
Visible
=
"false"
HeaderText
=
"Version"
AllowFiltering
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"fileDescription"
DataField
=
"fileDescription"
Visible
=
"true"
HeaderText
=
"Description"
AllowFiltering
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"filePath"
DataField
=
"filePath"
Display
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"fileName"
DataField
=
"fileName"
Display
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"originalFileName"
DataField
=
"originalFileName"
Visible
=
"false"
HeaderText
=
"Original File Name"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"active"
DataField
=
"active"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Open"
Text
=
"Open"
UniqueName
=
"OpenFile"
HeaderText
=
""
></
telerik:GridButtonColumn
>
</
Columns
>
<
CommandItemSettings
AddNewRecordText
=
"Add New Attachment"
RefreshText
=
"Refresh"
ShowAddNewRecordButton
=
"false"
/>
<
EditFormSettings
EditFormType
=
"Template"
FormStyle-Height
=
"100%"
FormStyle-Width
=
"100%"
PopUpSettings-ScrollBars
=
"Vertical"
>
<
FormTemplate
>
<
div
class
=
"row"
style
=
"padding-left:10px"
>
<
div
class
=
"col-sm-1"
>
<
asp:TextBox
ID
=
"FileNameText"
runat
=
"server"
CssClass
=
"form-control"
Text='<%# Bind("fileName") %>' >
</
asp:TextBox
>
</
div
>
<
div
class
=
"col-sm-1"
>
<
asp:TextBox
ID
=
"FilePathText"
runat
=
"server"
CssClass
=
"form-control"
Text='<%# Bind("filePath") %>' >
</
asp:TextBox
>
</
div
>
</
div
>
<
div
class
=
"col-sm-3"
>
<
div
class
=
"form-group"
>
<
label
>Version<
span
style
=
"color:red; font-size:large"
> *</
span
></
label
>
<
asp:RequiredFieldValidator
id
=
"RequiredFieldValidator2"
runat
=
"server"
ControlToValidate
=
"attachmentVersionList"
ErrorMessage
=
"REQUIRED!"
ForeColor
=
"Red"
Font-Size
=
"Medium"
Font-Bold
=
"true"
>
</
asp:RequiredFieldValidator
>
<
asp:DropDownList
ID
=
"attachmentVersionList"
runat
=
"server"
CssClass
=
"form-control"
AutoPostBack
=
"false"
ToolTip
=
"Required"
Width
=
"66%"
></
asp:DropDownList
>
</
div
>
</
div
>
<
div
class
=
"col-sm-1"
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
Visible
=
"true"
Text='<%# Bind("filePath") %>'></
asp:TextBox
>
<
asp:TextBox
ID
=
"TextBox2"
runat
=
"server"
Visible
=
"true"
Text='<%# Bind("fileName") %>'></
asp:TextBox
>
</
div
>
</
div
>
</
FormTemplate
>
</
EditFormSettings
>
<
NoRecordsTemplate
>
<
div
>
There are no attachments for this ticket.
</
div
>
</
NoRecordsTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
div
>
</
div
>
</
asp:Panel
>