Hi Nelviticus,
Thank U for Ur suggestion. It helped in solving my problem.
The followin code helps in checking the existance of storage card as well as reading the files from it.
using System;
using System.Drawing;
using System.Collections;
using System.IO;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
namespace FindFirstFileSample
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FindFirstFileSample : System.Windows.Forms.Form
{
const int MAX_PATH = 260;
/// <summary>
/// My Computer, which is a virtual folder that contains everything
/// on the local computer: storage devices, printers, and
/// Control Panel.
/// </summary>
const int CSIDL_DRIVES = 0x0011;
public class LibWrap
{
/// <summary>
/// This function retrieves the handle to the window, if any, that has
/// captured the mouse or stylus input. Only one window at a time can
/// capture the mouse or stylus input.
/// </summary>
/// <returns>The handle of the capture window associated with the current
/// thread indicates success. NULL indicates that no window in the current
/// thread has captured the mouse.</returns>
[DllImport("coredll.dll")]
public static extern IntPtr GetCapture();
/// <summary>
/// This function retrieves the path of a special folder, identified
/// by its CSIDL.
/// </summary>
/// <param name="hwndOwner">Handle to the owner window the client should
/// specify if it displays a dialog box or message box.</param>
/// <param name="lpszPath">Address of a character buffer that receives
/// the drive and path of the specified folder. This buffer must be at
/// least MAX_PATH characters in size.</param>
/// <param name="nFolder"> CSIDL that identifies the folder of interest.
/// If a virtual folder is specified, this function fails.</param>
/// <param name="fCreate">Indicates if the folder should be created if
/// it does not already exist. If this value is nonzero, the folder will
/// be created. If this value is zero, the folder will not be
/// created.</param>
/// <returns>Returns FALSE even if successful.</returns>
[DllImport("Coredll.dll")]
public static extern int SHGetSpecialFolderPath
(
IntPtr hwndOwner,
StringBuilder lpszPath,
int nFolder,
int fCreate
);
}
public FindFirstFileSample()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
try
{
//..Gets Handle to a window
IntPtr hwnd = LibWrap.GetCapture();
MessageBox.Show("Checking for storage cards...","Message");
bool bFoundOne = false;
DirectoryInfo rootDir = new DirectoryInfo("\\");
foreach (FileSystemInfo fsi in rootDir.GetFileSystemInfos())
{
if ((FileAttributes.Directory | FileAttributes.Temporary) == (fsi.Attributes & (FileAttributes.Directory | FileAttributes.Temporary)))
{
MessageBox.Show(fsi.Name,"File Name");
bFoundOne = true;
}
}
if (!bFoundOne)
MessageBox.Show("None found","Message");
//..Debug
MessageBox.Show("Finding Programs folder path","Message");
StringBuilder folderName = new StringBuilder(MAX_PATH);
//..Searches for the files in the Drives(storage card)
LibWrap.SHGetSpecialFolderPath(hwnd, folderName, CSIDL_DRIVES, 0);
if (string.Compare(folderName.ToString(), "") != 0)
{
MessageBox.Show(folderName.ToString(),"Folder Name");
}
else
{
MessageBox.Show("FAILURE : Not Found","Message");
}
}
catch(Exception exp)
{
//..Debug
MessageBox.Show(exp.ToString()+"\n"+exp.Message,"Unknown Error");
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// FindFirstFileSample
//
this.Text = "FindFirstFileSample";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new FindFirstFileSample());
}
}
}
Regards,
R.Venkatesh
MakeLogic
venkat@makelogicmldb.com