How to: Export Images from a Column of the CardViewImageColumn Type
- 2 minutes to read
The following example exports images displayed in the CardViewImageColumn. To export images, handle the RenderBrick event and populate its argument ImageValue property with an image in the binary format.
<table>
<tr>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnPdfExport" runat="server" Text="Export to PDF" OnClick="btnPdfExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsExport" runat="server" Text="Export to XLS" OnClick="btnXlsExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsxExport" runat="server" Text="Export to XLSX" OnClick="btnXlsxExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnRtfExport" runat="server" Text="Export to RTF" OnClick="btnRtfExport_Click" />
</td>
<td>
<dx:ASPxButton ID="btnCsvExport" runat="server" Text="Export to CSV" OnClick="btnCsvExport_Click" />
</td>
</tr>
</table>
<dx:ASPxCardView ID="CardView1" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
<Columns>
<dx:CardViewTextColumn Caption="Common Name" FieldName="Common_Name" VisibleIndex="0">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn Caption="Species Name" FieldName="Species_Name" VisibleIndex="1">
</dx:CardViewTextColumn>
<dx:CardViewImageColumn Caption="Image" FieldName="ImagePath" VisibleIndex="2">
<PropertiesImage ImageHeight="120px" ImageWidth="180px">
</PropertiesImage>
</dx:CardViewImageColumn>
</Columns>
</dx:ASPxCardView>
<dx:ASPxCardViewExporter CardWidth="310" ID="CardViewExporter" CardViewID="CardView1"
OnRenderBrick="ASPxCardViewExporter1_RenderBrick" runat="server" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Fishes.xml" />
using DevExpress.Web;
public partial class _Default : System.Web.UI.Page
{
protected void ASPxCardViewExporter1_RenderBrick(object sender, DevExpress.Web.ASPxCardViewExportRenderingEventArgs e) {
var dataColumn = e.Column as CardViewColumn;
if (dataColumn != null && dataColumn.FieldName == "ImagePath")
e.ImageValue = GetImageBinaryData(e.Value.ToString());
}
protected void btnPdfExport_Click(object sender, EventArgs e) {
CardViewExporter.WritePdfToResponse();
}
protected void btnXlsExport_Click(object sender, EventArgs e) {
CardViewExporter.WriteXlsToResponse();
}
protected void btnXlsxExport_Click(object sender, EventArgs e) {
CardViewExporter.WriteXlsxToResponse();
}
protected void btnRtfExport_Click(object sender, EventArgs e) {
CardViewExporter.WriteRtfToResponse();
}
protected void btnCsvExport_Click(object sender, EventArgs e) {
CardViewExporter.WriteCsvToResponse();
}
byte[] GetImageBinaryData(string relativePath) {
string path = Server.MapPath(relativePath);
return File.Exists(path) ? File.ReadAllBytes(path) : null;
}
}