Mohamad Mahmoud Mohamad Mahmoud - 3 months ago 40
ASP.NET (C#) Question

TransmitFile is not working

this code on ascx.cs file (Web User Control) ?!

protected void lnkOrderDetail_Command(object sender, CommandEventArgs e)
{
Telerik.Web.UI.GridDataItem item = gvAllDocuments.Items[int.Parse(e.CommandArgument.ToString())];
string FileName = item["documentFileName"].Text;
string PathString = @"C:\Documents\";
string SubPath = PathString + Utils.GetUserName() + "\\" + FileName;
FileInfo FileInfo1 = new FileInfo(SubPath);

Response.ClearContent();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName + "");
Response.ContentType = "text/HTML";
Response.AddHeader("Content-Length", FileInfo1.Length.ToString());


Response.TransmitFile(SubPath);
Response.End();
}

<asp:UpdatePanel ID="UpdatePanelDocuments" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="ViewDocumentsButton" runat="server" Text="View/Upload Documents" OnClick="ViewDocumentsButton_Click" />

<asp:PlaceHolder ID="UploadPlaceHolder" runat="server" Visible="false">

<hr />
<br />
<asp:Label Text="Document Type :" runat="server" ID="DocuemntLabel"></asp:Label>&nbsp;

<br />
<asp:Label Text="File :" runat="server" ID="FileLabel"></asp:Label>&nbsp;&nbsp;&nbsp;
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RegularExpressionValidator ID="uplValidator" runat="server" ControlToValidate="FileUpload1"
ErrorMessage=".png, jpg & pdf formats are allowed"
ValidationExpression="(.+\.([Pp][Nn][Gg])|.+\.([Jj][Pp][Gg])|.+\.([Pp][Dd][Ff]))"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="customValidatorUpload" runat="server" ErrorMessage="" ControlToValidate="FileUpload1" ClientValidationFunction="setUploadButtonState();" />
<br />

<asp:Button ID="btnUpload" runat="server" Text="Upload file" OnClick="Upload" Enabled="false" />&nbsp;&nbsp;
</asp:Label>
<br />
<br />

<telerik:RadGrid ID="gvAllDocuments" runat="server" AutoGenerateColumns="false"
AllowFilteringByColumn="true" RegisterWithScriptManager="true"
AllowPaging="true" PageSize="10">
<GroupingSettings CaseSensitive="false" />
<MasterTableView CommandItemSettings-ShowExportToExcelButton="false" CommandItemSettings-ShowRefreshButton="false" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemDisplay="Top">
<Columns>

<telerik:GridBoundColumn DataField="fileType" HeaderText="File Type" Visible="false"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="lnkOrderDetail" runat="server" Text="View" CommandArgument='<%#Container.ItemIndex%>' OnCommand="lnkOrderDetail_Command"></asp:Button>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Resizing AllowResizeToFit="true" />
</ClientSettings>
</telerik:RadGrid>
</asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>

</asp:UpdatePanel>


TransmitFile did not do anything ?!
i get the following error on web-console


Error: 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 '����N\Exif

Answer

this working fine for me because the button is include Telerik grid
i add the following :

<Triggers>
             <asp:PostBackTrigger ControlID="gvAllDocuments" />
  </Triggers>    
Comments