How can use upload image control in ?

Sanat Shukla

Total Post:19


Posted by  Sanat Shukla
C#  ASP.Net  OOPS 
 231  View(s)
Rate this:

Without using SQL Database...

  1. Re: How can use upload image control in ?

    Step 1. Open visual studio and select a webform

    How can use upload image control in ?

    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;
        protected void Upload(object sender, EventArgs e)
            if (FileUpload1.HasFile)
                string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/") + fileName);

    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" "">
    <html xmlns="">
    <head runat="server">
        <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">
                <asp:BoundField DataField="Text" />
                <asp:ImageField DataImageUrlField="Value" ControlStyle-Height="100" ControlStyle-Width="100" />

    Step 3. Add an Image folder in solution explorer

    How can use upload image control in ?

    Its use for only practice.

    Keep on reading....Thank you !! 


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.