aspnet-devexpress-dot-web-dot-aspxbinaryimage.md
Gets or sets an array of the bytes representing the image.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
[DefaultValue(null)]
public virtual byte[] ContentBytes { get; set; }
<DefaultValue(Nothing)>
Public Overridable Property ContentBytes As Byte()
| Type | Default | Description |
|---|---|---|
| Byte[] | null |
A Byte array that contains the image’s contents.
|
The example below demonstrates how to use the ASPxBinaryImage.ContentBytes property.
<dxwe:ASPxBinaryImage ID="biImage" runat="server">
</dxwe:ASPxBinaryImage>
<dxwuc:ASPxUploadControl runat="server" ID="ucImageUpload"
ClientInstanceName="ucImageUpload"
onfileuploadcomplete="ucImageUpload_FileUploadComplete">
<ValidationSettings AllowedFileExtensions=".jpg,.jpe,.jpeg,.gif">
</ValidationSettings>
</dxwuc:ASPxUploadControl>
<dxwe:aspxbutton id="btnUpload" runat="server" autopostback="False" text="Upload">
<ClientSideEvents Click="function(s, e) { ucImageUpload.UploadFile(); }" />
</dxwe:aspxbutton>
<dxwe:aspxbutton id="btnApply" runat="server" text="Apply image from session"
onclick="btnApply_Click">
</dxwe:aspxbutton>
protected void ucImageUpload_FileUploadComplete
(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
UploadedFile uploadFile = ucImageUpload.UploadedFiles.Length == 0 ?
null : ucImageUpload.UploadedFiles[0];
Session["UploadedImageBytes"] = uploadFile.FileBytes;
}
protected void btnApply_Click(object sender, EventArgs e) {
biImage.ContentBytes = (byte[])Session["UploadedImageBytes"];
}
Protected Sub ucImageUpload_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs)
Dim uploadFile As UploadedFile = If(ucImageUpload.UploadedFiles.Length = 0, Nothing, ucImageUpload.UploadedFiles(0))
Session("UploadedImageBytes") = uploadFile.FileBytes
End Sub
Protected Sub btnApply_Click(ByVal sender As Object, ByVal e As EventArgs)
biImage.ContentBytes = CType(Session("UploadedImageBytes"), Byte())
End Sub
View Example: How to display a bar code image in a column
The following code snippets (auto-collected from DevExpress Examples) contain references to the ContentBytes property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
asp-net-web-forms-grid-display-barcode-in-column/CS/ASPxGridViewBarCode/Default.aspx.cs#L20
if (value != null)
image.ContentBytes = GetBarCodeImage(value.ToString());
}
asp-net-web-forms-implement-pdf-viewer/CS/PdfViewer.ascx.cs#L109
bitmap.Save(stream, ImageFormat.Png);
image.ContentBytes = stream.ToArray();
}
asp-net-web-forms-grid-display-barcode-in-column/VB/ASPxGridViewBarCode/Default.aspx.vb#L25
If value IsNot Nothing Then
image.ContentBytes = GetBarCodeImage(value.ToString())
End If
asp-net-web-forms-implement-pdf-viewer/VB/PdfViewer.ascx.vb#L115
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
image.ContentBytes = stream.ToArray()
End Using
See Also