Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

Introduction

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.

License

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

Share

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.

Comments and Discussions

 
BugThanks a lot for the code. And I found one small bug (I think) PinmemberEilif Leknes11-Oct-12 20:51 
GeneralRe: Thanks a lot for the code. And I found one small bug (I think) PinmemberEric Shandil11-Oct-12 22:19 
GeneralRe: Thanks a lot for the code. And I found one small bug (I think) PinmemberEilif Leknes17-Oct-12 1:59 
QuestionThanks a Lot! PinmemberERMARC11-Oct-12 3:50 
AnswerRe: Thanks a Lot! PinmemberEric Shandil11-Oct-12 22:14 
Questionview files Pinmemberzygos291-Jan-09 3:33 
AnswerRe: view files PinmemberEric Shandil1-Jan-09 21:47 
AnswerRe: view files Pinmemberzygos295-Jan-09 6:27 
Generalwow .. COOL .. Very Nice .. and Very Helpfully Pinmemberhisoka_villian15-May-08 16:36 
GeneralRe: wow .. COOL .. Very Nice .. and Very Helpfully Pinmembershandile20-Aug-08 13:08 

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

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

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