本帖最后由 liumingfly 于 2010-04-02 00:33:03 编辑

解决方案 »

  1.   

    在DropDownList1中显示本地磁盘: ???????lz确信是web页面上取得本地磁盘??
      

  2.   

    请选择磁盘:     选择文件夹:    选择文件:        三个下拉列表
    当选择文件的时候,在选择文件下拉列表中显示文件夹下的所有txt文件.同时还要获取这时的txt的路径名,对它进行数据读取
      
      

  3.   

    意思是?如果选C盘,那就把C盘底下所有的txt文件显示出来?包括在子文件夹里的?
      

  4.   

    如果选C盘,第二个下拉列表则显示所有的C盘文件夹,当选择其中的一个文件夹时,第三个下拉列表这显示这个文件夹下的所有TXT文件....现在我想获得选择的TXT的文件路径去执行读取
      

  5.   


    private void GetFolders()
    {
        //iterate through all folders in photo dir  and bound to DataList
        //first we will get list of all folders,full path
          string gfolder=System.Configuration.ConfigurationSettings.AppSettings["photofolder"];
          string[] folders=System.IO.Directory.GetDirectories(Server.MapPath(gfolder));
       //get separate string as full parent name
          string parent=System.IO.Directory.GetParent(Server.MapPath(gfolder)).FullName+"\\"+gfolder+"\\";
          ViewState["parent"]=parent; //we want to keep this value
         //string parent=System.IO.Directory.GetParent(Server.MapPath("photo"));
         //will remove parent path to leave only actual folders name to use them as a link
         for (int i=0; i<=folders.Length-1; i++)
          {
     folders[i]=folders[i].Remove(0,parent.Length);

           }
        //bind source and get links to folders
         dlFolderList.DataSource=folders;     dlFolderList.DataBind();
    }
      

  6.   

    photofolder是配置文件里面的节点
    通过它取到它下面所有文件夹
    将它绑定到你的控件dlFolderList
    他可以是datalist或者是dropdownlist
      

  7.   

    三个下拉列表数据的绑定能够都是同一道理,在传值上采用网上比较流行的省市县下拉列表传值的方法就成,可以是无刷新的,当然也可以是每选择一次就autopostback一次
      

  8.   

    我要在其他的地方,怎么调用所选文件的路径呢?   teresa_tanxiaoguang
      

  9.   


    private void GetPhotos()
    { string photodir=System.Configuration.ConfigurationSettings.AppSettings["photofolder"]; //or get from config file string curGallery="";
    // use convention G is parameters to switch between galleries
    if (Request["G"]!=null)
    {
    curGallery=Request["G"]; //find where we are
    }
    else
    {
    curGallery=System.IO.Directory.GetDirectories(Server.MapPath(photodir))[0]; //if no parameters show first directory
    string parent=(string) ViewState["parent"];
    curGallery=curGallery.Substring(parent.Length);
    }
    // try get all files in folder
    try
    {
    //get thumbnails and photos arrays in current directory
    string[] photos=System.IO.Directory.GetFiles(Server.MapPath(photodir+"/"+curGallery),"*.jpg"); 
    // this array used if we have separate files as thumbnail images. Convention here to add _thumb to file name //string[] thumb=System.IO.Directory.GetFiles(Server.MapPath("photo/"+curGallery),"*_thumb*");
    //get directory info itself
    int i=System.IO.Directory.GetParent(Server.MapPath(photodir)).FullName.Length;
    //
    //get files names/ relative path
    //just get actual files names for thumbnails and photos
    //just removing extra path, leaving only catalog and file name
    for (int ix=0; ix<photos.Length; ix++)
    {
    photos[ix]=photos[ix].Substring(i+1);
    photos[ix]=photos[ix].Replace("\\","/");
    }
    listImg.DataSource=photos;
    listImg.DataBind();



    //find how many photos and how many pages to create pages
    int num=photos.Length;//it is number of photos
    //int num=thumb.Length; old usage
    lblPage.InnerText=num.ToString();
    if (num>10) imgbNext.Visible=true;

    //here we are using paged datasource
    PagedDataSource objPds = new PagedDataSource();
    //
    objPds.DataSource = photos; //we will show thumbnails 

    // Indicate that the data should be paged
    objPds.AllowPaging = true;

    // Set the number of items you wish to display per page
    objPds.PageSize = 10; //fixed page size, other option to control through drop down box.
    objPds.CurrentPageIndex = CurrentPage;
    ViewState["Pages"]=objPds.PageCount;
    //fill pages values for dropdown list
    //do it only first time
    if (!Page.IsPostBack)
    {
    dlPages.Items.Clear();
    for (int ip=1;ip<=objPds.PageCount;ip++)
    {
    dlPages.Items.Add(ip.ToString());
    }
    }
    else
    {
    //list already there, so just set the right page
    //dlPages.SelectedIndex=CurrentPage;
    } lblPage.InnerText=" Page "+(CurrentPage+1).ToString()+" of "+objPds.PageCount.ToString();
    //control visibility of next/prev buttons
    imgbPrev.Enabled = !objPds.IsFirstPage;
    //imgbPrev.Visible=!objPds.IsFirstPage;
    imgbNext.Enabled = !objPds.IsLastPage; 
    //imgbNext.Visible = !objPds.IsLastPage; 
    repPhotoG.DataSource=objPds;
    //
    //DIV1.InnerText=thumb.
    //gallery.Add()
    repPhotoG.DataBind(); 
    //we also will use item data bind events to add some links to thumbnails

    }
    catch (Exception ex)
    {
    //do something with error }

    //imgLarge.Attributes["onfilterchange"]="fade()";
    }我这个代码使用来取到文件夹下面的图片文件,同时绑定显示在页面上,图片所在的根文件夹是在webconfig当中配置好了的,楼主同学可以参考,不建议你在页面当中把真实路径显示出来,从安全的角度来说实在是不恰当,如果楼主果真需要那么做最笨的办法就是拼接字符串,再者就是单独写一个函数gettxturl()实质上也是起到拼接串的作用
      

  10.   

    teresa_tanxiaoguang能不能根据我的代码帮我改下,因为第三列表选择的是第二个列表的所以txt文件.不知道它经过几次递归获得文件.
    我现在想获得文件的路径.然后在其他button中读取数据...谢谢了
      

  11.   

    经过递归之后,路径就不能拼接字符串了.string path = "" + DropDownList1.SelectedItem.Text + ":\\" + DropDownList2.SelectedItem.Text + "\\" + DropDownList3.SelectedIndex;这个路径就不正确了.请告诉我怎么获得这个路径因为我在
     protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string path = "" + DropDownList1.SelectedItem.Text + ":\\" + DropDownList2.SelectedItem.Text + "\\" + DropDownList3.SelectedIndex;
                StreamReader reader = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"));
                string oneline;
                DataTable dt = new DataTable();
                dt.Columns.Add("dbID", typeof(string));
                dt.Columns.Add("商业站点", typeof(string));
                while ((oneline = reader.ReadLine()) != null)
                {
                    DataRow row = dt.NewRow();
                    oneline = oneline.Trim();
                    if (oneline != "")
                    {
                        string[] ss = oneline.Split(".".ToCharArray());
                        row[0] = ss[0];
                        row[1] = ss[1];
                        dt.Rows.Add(row.ItemArray);
                    }
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('文件格式不符合');</script>");
            }
        }要调用这个文件的path
      

  12.   

    能不能加我Q:506969887   teresa_tanxiaoguang