ASP Net Controls ASP.Net Tutorial

Important properties, events
Enabled:      disable the FileUpload control.
FileBytes:    get the uploaded file as a byte array.
FileContent:  get the uploaded file as a stream.
FileName:     get the name of the file uploaded.
HasFile:      Returns True when a file has been uploaded.
PostedFile:   get the uploaded file wrapped in the HttpPostedFile object.
Focus:        set the form focus to the FileUpload control.
SaveAs:       save the uploaded file to the file system.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (upImage.HasFile)
        {
            if (CheckFileType(upImage.FileName))
            {
                String filePath = "~/UploadImages/" + upImage.FileName;
                upImage.SaveAs(MapPath(filePath));
            }
        }
    }
    bool CheckFileType(string fileName)
    {
        string ext = Path.GetExtension(fileName);
        switch (ext.ToLower())
        {
            case ".png":
                return true;
            case ".jpg":
                return true;
            default:
                return false;
        }
    }
    void Page_PreRender()
    {
        string upFolder = MapPath("~/UploadImages/");
        DirectoryInfo dir = new DirectoryInfo(upFolder);
        dlstImages.DataSource = dir.GetFiles();
        dlstImages.DataBind();
    }



    FileUpload File


    
    

            id="lblImageFile"
        Text="Image File:"
        AssociatedControlID="upImage"
        Runat="server" />
            id="upImage"
        Runat="server" />
    
            id="btnAdd"
        Text="Add Image"
        OnClick="btnAdd_Click"
        Runat="server" />
    
            id="dlstImages"
        RepeatColumns="3"
        runat="server">
        
                    ImageUrl='<%# Eval("Name", "~/UploadImages/{0}") %>'
            style="width:200px"
            Runat="server" />
        
        <%# Eval("Name") %>