Click here to Skip to main content
13,553,325 members
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 11 Feb 2007
Licenced CPOL

MSSQL/MSDE Server Folder Browser

, 11 Feb 2007
Rate this:
Please Sign up or sign in to vote.
Browse for folder on computer with MS SQL Server from a remote computer.


I have looked everywhere to get either some direction or help on how to get the lists of folders and drives of a computer installed with Microsoft SQL Server and/or MSDE from a Windows based application on a remote computer connecting to the server. I have finally drawn a solution to accomplish this task. Most of the code is self-explanatory and documented, so I will leave the detailed explanation out.

To kick things off, first we need to get connected to the Master database of the server, since we will be using some Stored Procedure that only exists in the Master database.

Let's dissect the 'SQLServerFolderBrowse class' a bit. These are some un-documented procedures, and the names are self-explanatory:

  • xp_fixeddrives
  • xp_availablemedia
  • xp_subdirs

I have created some properties to set the connection property so that the class structure is maintained. These properties are set in the function fxnConnection; however, I would recommend that you apply the properties when calling the dialog from your calling form.

There are four functions in this class that carry out the entire work of getting the drives, folders, and sub-folders, namely:

  • GetFixedDrives - gets the installed drive letters on the MS SQL computer.
  • GetAvailableDrives - gets all the drives on which the writing can be carried out.
  • GetSubFolders - this function requires a parameter, parent, and as the name specifies is used to get the folders in the parent.
  • InitializeConnection - checks if the connection string is not empty, and sets the connection string otherwise.

We have completed the algorithm of getting the required solution. Now, we need an interface between the program and the user. I have created a dialog box that mimics the Windows folder browser. Please look through the code for a complete documentation. Briefly, the code-behind is divided into regions for readability. In the function region, you set the parameters to connect to the master database of the server in the function fxnConnect. However, I recommend that you use the dialog browser object to set these properties. In the function region, the treeview is filled with the list of drives, folders, and sub-folders. Folders that contain the sub folders are assigned a subfolder 'Dummy' to increase the performance of the control. Once the user expands a folder, the sub-folders are populated under the parent folder. Now, your interface is created and you are ready to use the dialog. See 'frmTest' on how to use the control.

A timer is used to check if the dialog box has been closed to fill the appropriate control on the calling windows. The browser dialog can be opened as modal, but for MSI projects, you may have to use the mentioned procedure and provide a parameter indicating the calling form with the initializing dialog form (Me). Please browse through the code, and if you find any difficulty, please feel free to contact me.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Eric Shandil
Software Developer (Senior) Business Software Solutions
Fiji Fiji
I started as a part-time tutor at the University of the South Pacific, then I work as a programmer using MSAccess 97-2003, VB 6.0 VB .NET 1.0, VB .NET 1.1, MSSQL, MySQL, Oracle and Firebird for three years of which I have spent two years as a I.T. Manager for a manufacturing industry. Due to increasing demand in integrated software solutions specific to Fiji, I joined a software consulting company, so far I have develped a payroll, time and attendance, HRIS, municipality, accounting and POS software.

I provide software and administration consulting for a number companies in Fiji.

I am also interested in overseas contracts for Windows/Linux based design and developments.

I currently hold BSc in computing Sci and Physics and MCP.

You may also be interested in...


Comments and Discussions

QuestionNot working Pin
kevin.dmonte4-May-15 23:55
memberkevin.dmonte4-May-15 23:55 
BugThanks a lot for the code. And I found one small bug (I think) Pin
Eilif Leknes11-Oct-12 20:51
memberEilif Leknes11-Oct-12 20:51 
GeneralRe: Thanks a lot for the code. And I found one small bug (I think) Pin
Eric Shandil11-Oct-12 22:19
memberEric Shandil11-Oct-12 22:19 
GeneralRe: Thanks a lot for the code. And I found one small bug (I think) Pin
Eilif Leknes17-Oct-12 1:59
memberEilif Leknes17-Oct-12 1:59 
QuestionThanks a Lot! Pin
ERMARC11-Oct-12 3:50
memberERMARC11-Oct-12 3:50 
AnswerRe: Thanks a Lot! Pin
Eric Shandil11-Oct-12 22:14
memberEric Shandil11-Oct-12 22:14 
Questionview files Pin
zygos291-Jan-09 3:33
memberzygos291-Jan-09 3:33 
AnswerRe: view files Pin
Eric Shandil1-Jan-09 21:47
memberEric Shandil1-Jan-09 21:47 
AnswerRe: view files Pin
zygos295-Jan-09 6:27
memberzygos295-Jan-09 6:27 
Generalwow .. COOL .. Very Nice .. and Very Helpfully Pin
hisoka_villian15-May-08 16:36
memberhisoka_villian15-May-08 16:36 
GeneralRe: wow .. COOL .. Very Nice .. and Very Helpfully Pin
shandile20-Aug-08 13:08
membershandile20-Aug-08 13:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 11 Feb 2007
Article Copyright 2007 by Eric Shandil
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid