aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.Net Image Upload and Preview without Saving in Folder using C#, VB.NET

Jun 13, 2016

Here I will explain how to upload and show / display image without saving in using c#, with example or image upload and preview without saving in folder in using c#, with example or display image in image control after upload in without saving to folder using c#, with example. By using binaryreader property in we can upload and display image without saving in folder using c#,

To upload and display image in without saving in folder we to create new website in visual studio and open your aspx page and write the following code

<html xmlns="">
<head runat="server">
<title>ASP.Net Upload and Preview Image without saving in C#, VB.Net</title>
<style type="text/css">
<form id="form1" runat="server">
<div style=" width:50%">
<asp:FileUpload ID="upload1" runat="server" />
<asp:Button ID="btnPreview" runat="server" Text="Upload & Preview" onclick="btnPreview_Click" />
<hr />
<asp:Image ID="imgDetail" Visible = "false" runat="server" />

After adding code in aspx page now open code behind file and add following namespaces

C# Code

using System;
using System.IO;

After completion of adding namespaces you need to write the code like as shown below

protected void btnPreview_Click(object sender, EventArgs e)
Stream strm = upload1.PostedFile.InputStream;
BinaryReader reader = new BinaryReader(strm);
Byte[] bytes = reader.ReadBytes(Convert.ToInt32(strm.Length));
imgDetail.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
imgDetail.Visible = true;


Imports System.IO
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim strm As Stream = upload1.PostedFile.InputStream
Dim reader As New BinaryReader(strm)
Dim bytes As [Byte]() = reader.ReadBytes(Convert.ToInt32(strm.Length))
imgDetail.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length)
imgDetail.Visible = True
End Sub
End Class


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.