Should CNET request. Hand over the catalogue browsing class. This was written a few months ago. (from ASP.net edition)

Source: Internet
Author: User
Tags tostring root directory
asp.net using System;
Using System.Text;
Using System.Windows.Forms;
Using System.Runtime.InteropServices;

Namespace Blood.Com.ClassLib
{
<summary>
Directory dialog box control
</summary>
public class Directorydialog
{
[StructLayout (LayoutKind.Sequential, Charset=charset.ansi)]
<summary>
Browse Information
</summary>
public struct BROWSEINFO
{
Public IntPtr hWndOwner;
public int pidlroot;
public string pszDisplayName;
public string Lpsztitle;
public int ulflags;
public int lpfncallback;
public int lParam;
public int iimage;
}

Private Const int MAX_PATH = 260;
<summary>
Specify browse type
</summary>
public enum Browsefortypes
{
<summary>
Browsing computers
</summary>
Computers = 0x1000,
<summary>
Browse Catalog
</summary>
directories = 0x1,
<summary>
Browse Directories and files
</summary>
<remarks> can only work on versions of 4.71 or higher <remarks>
Filesanddirectories = 0x4000,//4.71 Edition
<summary>
Browse system root Directory
</summary>
Filesystemancestors = 0x8
}

[DllImport ("Ole32.dll")]
private static extern int CoTaskMemFree (IntPtr hmem);
[DllImport ("kernel32.dll")]
private static extern IntPtr Lstrcat (string lpString1, string lpString2);
[DllImport ("Shell32.dll")]
private static extern IntPtr SHBrowseForFolder (ref browseinfo LPBI);
[DllImport ("Shell32.dll")]
private static extern int SHGetPathFromIDList (IntPtr pidlist, StringBuilder lpbuffer);
<summary>
Show public Folder dialog box
</summary>
<param name= "hWndOwner" > Folder dialog box owner </param>
protected bool RunDialog (INTPTR hWndOwner)
{
Browseinfo Udtbi = new Browseinfo ();
IntPtr lpIDList;
GCHandle htitle = GCHandle.Alloc (Title, gchandletype.pinned);
Set the owner of Windows
Udtbi.hwndowner = hWndOwner;
Set the owner of Windows
Udtbi.lpsztitle = Title;
Set the owner of Windows
Udtbi.ulflags = (int) browsefor;
Create a string buffer to display the name
StringBuilder buffer = new StringBuilder (MAX_PATH);
Buffer. Length = MAX_PATH;
Udtbi.pszdisplayname = buffer. ToString ();
Show Browse Directory dialog box
lpIDList = SHBrowseForFolder (ref UDTBI);
Htitle.free ();
if (Lpidlist.toint64 ()!= 0)
{
if (browsefor = = browsefortypes.computers)
{
m_selected = UdtBI.pszDisplayName.Trim ();
}
Else
{
StringBuilder path = new StringBuilder (MAX_PATH);
Get the path from the lpIDList
SHGetPathFromIDList (lpidlist, path);
m_selected = path. ToString ();
}
Free memory
CoTaskMemFree (lpIDList);
}
Else
{
return false;
}
return true;
}
<summary> Show Public Folders dialog box </summary>
Public DialogResult ShowDialog ()
{
return ShowDialog (NULL);
}
<summary>shows the Common folder dialog.</summary>
<param name= "owner" >the owner of the folder dialog.</param>
Public DialogResult ShowDialog (IWin32Window owner)
{
INTPTR handle;
if (owner!= null)
Handle = owner. Handle;
Else
handle = IntPtr.Zero;
if (RunDialog (handle))
{
return DialogResult.OK;
}
Else
{
return dialogresult.cancel;
}
}

<summary>
Specify the title of the dialog box
</summary>
<value> dialog box title </value>
<exceptions cref= "ArgumentNullException" > Null (vb.net is nothing) throws an error </exceptions>
public string Title
{
Get
{
return m_title;
}
Set
{
if (value = = null)
throw new ArgumentNullException ();
M_title = value;
}
}
<summary> Return selected Items </summary>
<value> Selected Projects </value>
public string Selected
{
Get
{
return m_selected;
}
}
<summary> Specify browse Type </summary>
<value> Browse Type </value>
Public Browsefortypes Browsefor
{
Get
{
return m_browsefor;
}
Set
{
M_browsefor = value;
}
}
Declaring private variables
Private Browsefortypes m_browsefor = browsefortypes.directories;
private string m_title = "";
private string m_selected = "";

<summary>
Constructors
</summary>
Public Directorydialog ()
{
//
TODO: Add constructor logic here
//
}
}
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.