Currently am working on the GridAttachment Column ,I placed the Rad Grid inside the Update Panel, On the Item Command event am d,i have written the download attachment code.But after clicking on Attachment item link in the Rad Grid amd getting Javascript Parser exception.
Please cgo thtough the below code,suggest me if am doing wrong
Aspx
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<
asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<
telerik:RadGrid ID="RadGrid2" AllowPaging="True"
ShowFooter="true" runat="server" AutoGenerateColumns="False" AllowSorting="True"
PageSize="3" GridLines="None" OnItemCommand="RadGrid2_ItemCommand" CellPadding="0" AllowAutomaticInserts="true"
AllowAutomaticUpdates="true">
<ClientSettings AllowRowsDragDrop="true"></ClientSettings>
<MasterTableView DataKeyNames="Id" AutoGenerateColumns="false" CommandItemDisplay="Top">
<Columns>
<telerik:GridAttachmentColumn DataSourceID="Id"
MaxFileSize="1048576"
EditFormHeaderTextFormat="Upload File:"
HeaderText="Download"
AttachmentDataField="BinaryData"
AttachmentKeyFields="Id"
FileNameTextField="AttachmentFile"
DataTextField="AttachmentFile"
UniqueName="AttachmentFile">
</telerik:GridAttachmentColumn >
</Columns>
</MasterTableView>
</telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadGrid2.DataSource =
TestData.GetEmployeeData();
RadGrid2.DataBind();
}
}
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
{
//upd.Update();
if (e.CommandName == "DownloadAttachment")
{
LinkButton btn = e.CommandSource as LinkButton;
string fileName1 = "images\\about.png";
/*
For testing purpose we took only a test image
* you can look at the e.CommandSource to know which row was clicked by
* checking the linkbutton.Text property(LinkButton btn = e.CommandSource as LinkButton;)
*/
FileInfo file = new FileInfo(Server.MapPath(fileName1));
NameValueCollection imageExtensions = new NameValueCollection();
imageExtensions.Add(
".jpg", "image/jpeg");
imageExtensions.Add(
".gif", "image/gif");
imageExtensions.Add(
".png", "image/png");
MemoryStream ms = new MemoryStream();
if (imageExtensions.AllKeys.Contains(file.Extension))
{
Response.Clear();
Response.ContentType = imageExtensions.Get(file.Extension);
Response.AppendHeader(
"Content-Disposition", "attachment; filename=" + file.Name);
Response.TransmitFile(file.FullName);
Response.End();
}
}
}