---
title: "How can use upload image control in asp.net ?"  
description: "How can use upload image control in asp.net ?"  
author: "Anonymous User"  
published: 2019-09-07  
updated: 2019-09-07  
canonical: https://www.mindstick.com/forum/95341/how-can-use-upload-image-control-in-asp-dot-net  
category: "c#"  
tags: ["c#", "asp.net", "oops"]  
reading_time: 2 minutes  

---

# How can use upload image control in asp.net ?

Without using [SQL Database](https://www.mindstick.com/articles/337535/connecting-to-sql-databases-ado-dot-net-essentials)...

## Replies

### Reply by Anonymous User

**Step 1.** Open visual studio and select a webform

![How can use upload image control in asp.net ?](https://www.mindstick.com/mindstickforums/4dc872be-0edd-4f57-9159-9c6f7fd624f7/images/86730c32-3c0d-41b9-8ef6-c59cccdd25bf.png)\

Code for abc.cs (Name of Page)

```
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections.Generic;

public partial class CS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string[] filePaths = Directory.GetFiles(Server.MapPath("~/Images/"));
            List<ListItem> files = new List<ListItem>();
            foreach (string filePath in filePaths)
            {
                string fileName = Path.GetFileName(filePath);
                files.Add(new ListItem(fileName, "~/Images/" + fileName));
            }
            GridView1.DataSource = files;
            GridView1.DataBind();
        }
    }
    protected void Upload(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/") + fileName);
            Response.Redirect(Request.Url.AbsoluteUri);
        }
    }
}
```

**Step 2.** Code for abc.aspx

```
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />
    <hr />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowHeader="false">
        <Columns>
            <asp:BoundField DataField="Text" />
            <asp:ImageField  DataImageUrlField="Value" ControlStyle-Height="100" ControlStyle-Width="100" />
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>
```

**Step 3.** Add an Image folder in solution explorer

![How can use upload image control in asp.net ?](https://www.mindstick.com/mindstickforums/4dc872be-0edd-4f57-9159-9c6f7fd624f7/images/86730c32-3c0d-41b9-8ef6-c59cccdd25bf.png)\

Its use for only practice.

Keep on reading....Thank you !!


---

Original Source: https://www.mindstick.com/forum/95341/how-can-use-upload-image-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
