asp.net 有一个自带的 FileUpload 文件上传控件,这个只能选择一个文件却不能选择一个文件夹我想实现的是选择一个文件夹点确定后获取这个文件夹的绝对地址,这个怎么实现,到网上找了好多资料但都不行,更奇怪的是在网上找了一段代码后,弹出的对话框的中间却没有选择文件一项,其它如新建文件夹,确定和取消按钮都有,就是没有中间选择文件夹的部分,不知为什么,下面是这段代码,请大家帮忙看一下        //创建FolderBrowserDialog类的实例
        FolderBrowserDialog fbd = new FolderBrowserDialog();        //指定上面部分的说明Text
        fbd.Description = "请指定文件夹。";
        //指定根目录
        //根目录为Desktop
        fbd.RootFolder = Environment.SpecialFolder.Desktop;
        //指定初始化目录
        //RootFolder以下的文件夹是有必要的
        fbd.SelectedPath = @"C:\Windows";
        //为了用户能创建新的文件夹
        //默认为True
        fbd.ShowNewFolderButton = true;        //显示对话框
        if (fbd.ShowDialog() == DialogResult.OK)
        {
            //显示选定的文件夹
            Console.WriteLine(fbd.SelectedPath);
        }

解决方案 »

  1.   

    activex选择文件夹,安全性问题
    var Shell = new ActiveXObject( "Shell.Application" );
      var Folder = Shell.BrowseForFolder(0,Message,0x0040,0x11);//起始目录为:我的电脑
      

  2.   

    试试哥的代码<%@ Page Language="C#" AutoEventWireup="true" CodeFile="20100824,2.aspx.cs" Inherits="_20100824_2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:fileupload runat="server" ID="fileupload1"></asp:fileupload>
        <asp:Button ID="BtnGetDirPath" runat="server"  Text="获取目录名字" 
                onclick="BtnGetDirPath_Click"  />
        </div>
        </form>
    </body></html>
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class _20100824_2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void BtnGetDirPath_Click(object sender, EventArgs e)
        {
            if (this.fileupload1.HasFile)
            {
                string path = this.fileupload1.FileName;
                string Dirpath = this.fileupload1.PostedFile.FileName.Replace(path,"");
                Response.Write("您选的目录名称是:"+Dirpath);  
            }
        }
    }哥的工具是VS2008