修改文件名称

protected void Page_Load(object sender, EventArgs e)
{

     if (!IsPostBack)
     {
         ddl();
         TextBox1.Text = DropDownList1.SelectedValue.ToString();
     }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
     TextBox1.Text = DropDownList1.SelectedValue.ToString();

}
protected void Button1_Click(object sender, EventArgs e)
{
     string path = Server.MapPath("File/") + DropDownList1.SelectedValue.ToString();
     FileInfo fi = new FileInfo(path);
     if (fi.Exists)
     {
         string path1 = Server.MapPath("File/") + TextBox1.Text;
         fi.MoveTo(path1);
     }
     ddl();

}
public void ddl()
{
     DirectoryInfo dir = new DirectoryInfo(Server.MapPath("file"));
     DataTable dt = new DataTable();
     dt.Columns.Add(new DataColumn("Name", typeof(string)));
 
  
     foreach (FileInfo fileName in dir.GetFiles())
     {
         DataRow dr = dt.NewRow();
         dr[0] = fileName;
         dt.Rows.Add(dr);
     }
     DropDownList1.DataSource = dt;
     DropDownList1.DataTextField = "Name";
     DropDownList1.DataValueField = "Name";
 
     DropDownList1.DataBind();
}

posted @ 2013-04-22 21:39  侯伟东  阅读(186)  评论(0编辑  收藏  举报