在System.IO里面有Directory ,DirectoryInfo,File ,FileInfo等类

解决方案 »

  1.   

    这些Directory ,DirectoryInfo,File ,FileInfo当然不行了,如果要到网络路径怎么办?
      

  2.   

    试试System.Windows.Forms.FolderBrowserDialog
      

  3.   

    .net2003 里面有目录选择框。
    或者在.net7里面引用vb.net的commondialog.
          private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox drlb;
          private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dlb;
          private Microsoft.VisualBasic.Compatibility.VB6.FileListBox flb;
      

  4.   

    下面的代码忘了是从哪里找到的了using System;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Collections;  
    /// <summary>
    /// Summary description for FolderBrowser.
    /// </summary>
    /// [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    [ComVisible(true)]
    public class BROWSEINFO 
    {
    public IntPtr hwndOwner;
    public IntPtr pidlRoot;
    public IntPtr pszDisplayName;
    public string lpszTitle;
    public int ulFlags;
    public IntPtr lpfn;
    public IntPtr lParam;
    public int iImage;
    } [Flags, Serializable]
    public enum BrowseFlags 
    {
    BIF_DEFAULT    = 0x0000, BIF_BROWSEFORCOMPUTER = 0x1000, BIF_BROWSEFORPRINTER = 0x2000, BIF_BROWSEINCLUDEFILES = 0x4000, BIF_BROWSEINCLUDEURLS = 0x0080, BIF_DONTGOBELOWDOMAIN = 0x0002, BIF_EDITBOX    = 0x0010, BIF_NEWDIALOGSTYLE  = 0x0040, BIF_NONEWFOLDERBUTTON = 0x0200, /// </summary>
    BIF_RETURNFSANCESTORS = 0x0008, BIF_RETURNONLYFSDIRS = 0x0001, BIF_SHAREABLE   = 0x8000, BIF_STATUSTEXT   = 0x0004, BIF_UAHINT    = 0x0100, BIF_VALIDATE   = 0x0020, BIF_NOTRANSLATETARGETS = 0x0400,

    public class API 
    {
    [DllImport("shell32.dll", PreserveSig=true, CharSet=CharSet.Auto)]
    public static extern IntPtr SHBrowseForFolder(BROWSEINFO bi); [DllImport("shell32.dll", PreserveSig=true, CharSet=CharSet.Auto)]
    public static extern bool SHGetPathFromIDList(IntPtr pidl, IntPtr pszPath); [DllImport("shell32.dll", PreserveSig=true, CharSet=CharSet.Auto)]
    public static extern int SHGetSpecialFolderLocation(IntPtr hwnd, int csidl, ref IntPtr ppidl);
    }
    public class FolderBrowser 
    {
    private string m_strDirectoryPath;
    private string m_strTitle;
    private string m_strDisplayName;
    private BrowseFlags m_Flags;
    public FolderBrowser()
    {
    //
    // TODO: Add constructor logic here
    //可以定制对话框外观
    m_Flags = BrowseFlags.BIF_DEFAULT;
    m_strTitle = ""; } public string DirectoryPath 
    {
    get{return this.m_strDirectoryPath;}
    }
    public string DisplayName 
    {
    get{return this.m_strDisplayName;}
    }
    public string Title 
    {
    set{this.m_strTitle = value;}
    }
    public BrowseFlags Flags 
    {
    set{this.m_Flags = value;}
    }
    public DialogResult ShowFolderBrowser() 
    {
       
    BROWSEINFO bi = new BROWSEINFO();
    bi.pszDisplayName = IntPtr.Zero;
    bi.lpfn = IntPtr.Zero;
    bi.lParam = IntPtr.Zero;
    bi.lpszTitle = "Select Folder";
    IntPtr idListPtr = IntPtr.Zero;
    IntPtr pszPath = IntPtr.Zero;
    try 
    {
    if (this.m_strTitle.Length != 0) 
    {
    bi.lpszTitle = this.m_strTitle;
    }
    bi.ulFlags = (int)this.m_Flags;
    bi.pszDisplayName = Marshal.AllocHGlobal(256);
       
    idListPtr = API.SHBrowseForFolder(bi);
      
    if (idListPtr == IntPtr.Zero) 
    {
    return DialogResult.Cancel;
    }  
    pszPath = Marshal.AllocHGlobal(256);
      
    bool bRet = API.SHGetPathFromIDList(idListPtr, pszPath);
      
    m_strDirectoryPath = Marshal.PtrToStringAuto(pszPath);
    this.m_strDisplayName = Marshal.PtrToStringAuto(bi.pszDisplayName);
    }
    catch (Exception ex) 
    {
    Trace.WriteLine(ex.Message);
    return DialogResult.Abort;
    }
    finally 
    {
       
    if (idListPtr != IntPtr.Zero) 
    {
    Marshal.FreeHGlobal(idListPtr);
    }
    if (pszPath != IntPtr.Zero) 
    {
    Marshal.FreeHGlobal(pszPath);
    }
    if (bi != null) 
    {
    Marshal.FreeHGlobal(bi.pszDisplayName);
    }
    }
    return DialogResult.OK;
    }
    }
      

  5.   

    1.1的话,就有专门的FolderBrowserDialog 类一下就变简单了。
      

  6.   

    目录选择
    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306285