Critical Developers

Programmers Knowledge Base

Bind Files in DropDownList from Server


Bind Files in DropDownList from Server
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class banner : System.Web.UI.Page
{
    protected string dirPath;
    protected int dirPathLength;
    protected String[] files;
    public string strEmbed = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["bid"] != null)
            {
                getfilename();
            }
        }
    }

    public void getfilename()
    {
        ArrayList values = new ArrayList();
        dirPath = Server.MapPath("../banners/");
        dirPathLength = dirPath.Length;
        dirPathLength = dirPathLength + 1;
        files = Directory.GetFiles(dirPath, "*.*");
        for (int i = 0; i < files.Length; i++)
        {
            string FileName = files[i];
            FileName = FileName.Replace(Server.MapPath("../banners/"), "");
            values.Add(FileName);
        }
        ddlselect.DataSource = values;
        ddlselect.DataBind();
        ddlselect.Items.Insert(0, "--Select--");
    }
}

Comments are closed