Asp.Net Show Image from Byte Array

We can show Image from Byte Array

ASP.Net control

     <asp:Image ID="Image1" runat="server" />

Server Side C# Code

		//Get File Bytes         
        Byte[] bytes = flUpload.FileBytes;

        //Convert to Base 64 
        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
      
        //Show using ImageURL properties 
        Image1.ImageUrl = "data:image/png;base64," + base64String;

Show Image

Advertisement

Asp.Net File Upload Validation

RegularExpression For File upload Control


 <asp:FileUpload ID="flUpload" runat="server" />
 <asp:RequiredFieldValidator ID="rfvFileUpload" ControlToValidate="flUpload" runat="server"  ErrorMessage="Please select File."></asp:RequiredFieldValidator>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="flUpload"
                            ErrorMessage="Only .jpg,.png,.jpeg,.gif Files are allowed" Font-Bold="True" Font-Size="Medium"
                            ValidationExpression="(.*?)\.(jpg|jpeg|png|gif|JPG|JPEG|PNG|GIF)$" Width="360px"></asp:RegularExpressionValidator>

File Upload