Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Virtual Drive

145 views
Skip to first unread message

Kavitha

unread,
Jul 28, 2006, 6:16:01 AM7/28/06
to
Hi ,
Can any one tel me how to create a virtual drive in C#( similar to
Gmail Virtual drive).Also tell me what interfaces could be used to create the
same.

Thanks in Advance
Kavitha

Ignacio Machin ( .NET/ C# MVP )

unread,
Jul 28, 2006, 10:36:16 AM7/28/06
to
Hi,

there is nothing in the framework for that.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Kavitha" <Kav...@discussions.microsoft.com> wrote in message
news:95B691FF-398C-4F84...@microsoft.com...

Steve Barnett

unread,
Jul 29, 2006, 5:42:09 AM7/29/06
to
Don't know anything about GMail or it's virtual drive facilities, so this
may not help in the slightest. I have a class that I use on the local PC to
map a folder to a drive letter, so I can, for example, map
d:\dev\source\MSVC\Tree to a virtual "j:" drive. Is that what's wanted?

I've reproduced the code below, just in case it has some relevance...

Steve

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace MapFolder
{
class VolumeFunctions
{
[DllImport("kernel32.dll")]
internal static extern bool DefineDosDevice(uint dwFlags, string
lpDeviceName,
string lpTargetPath);

[DllImport("Kernel32.dll")]
internal static extern uint QueryDosDevice(string lpDeviceName,
StringBuilder lpTargetPath, uint ucchMax);

internal const uint DDD_RAW_TARGET_PATH = 0x00000001;
internal const uint DDD_REMOVE_DEFINITION = 0x00000002;
internal const uint DDD_EXACT_MATCH_ON_REMOVE = 0x00000004;
internal const uint DDD_NO_BROADCAST_SYSTEM = 0x00000008;

const string MAPPED_FOLDER_INDICATOR = @"\??\";

// ----------------------------------------------------------------------------------------
// Class Name: VolumeFunctions
// Procedure Name: MapFolderToDrive
// Purpose: Map the folder to a drive letter
// Parameters:
// - driveLetter (string) : Drive letter in the format "C:"
without a back slash
// - folderName (string) : Folder to map without a back slash
// ----------------------------------------------------------------------------------------
internal static string MapFolderToDrive(string driveLetter, string
folderName)
{
// Is this drive already mapped? If so, we don't remap it!
StringBuilder volumeMap = new StringBuilder(1024);
QueryDosDevice(driveLetter, volumeMap, (uint)1024);
if (volumeMap.ToString().StartsWith(MAPPED_FOLDER_INDICATOR) ==
true)
return "Volume is already mapped - map not changed";

// Map the folder to the drive
DefineDosDevice(0, driveLetter, folderName);

// Display a status message to the user.
string statusMessage = new
Win32Exception(Marshal.GetLastWin32Error()).ToString();
return statusMessage.Substring(statusMessage.IndexOf(":") + 1);
}

// ----------------------------------------------------------------------------------------
// Class Name: VolumeFunctions
// Procedure Name: UnmapFolderFromDrive
// Purpose: Unmap a drive letter. We always unmp the drive,
without checking the
// folder name.
// Parameters:
// - driveLetter (string) : Drive letter to be released, the the
format "C:"
// - folderName (string) : Folder name that the drive is mapped
to.
// ----------------------------------------------------------------------------------------
internal static string UnmapFolderFromDrive(string driveLetter,
string folderName)
{
DefineDosDevice(DDD_REMOVE_DEFINITION, driveLetter, folderName);

// Display the status of the "last" unmap we run.
string statusMessage = new
Win32Exception(Marshal.GetLastWin32Error()).ToString();
return statusMessage.Substring(statusMessage.IndexOf(":") + 1);
}

// ----------------------------------------------------------------------------------------
// Class Name: VolumeFunctions
// Procedure Name: DriveIsMappedTo
// Purpose: Returns the folder that a drive is mapped to. If not
mapped, we return a blank.
// Parameters:
// - driveLetter (string) : Drive letter in the format "C:"
// ----------------------------------------------------------------------------------------
internal static string DriveIsMappedTo(string driveLetter)
{
StringBuilder volumeMap = new StringBuilder(512);
string mappedVolumeName = "";

// If it's not a mapped drive, just remove it from the list
uint mapped = QueryDosDevice(driveLetter, volumeMap, (uint)512);
if (mapped != 0)
if (volumeMap.ToString().StartsWith(MAPPED_FOLDER_INDICATOR)
== true)
{
// It's a mapped drive, so return the mapped folder name
mappedVolumeName = volumeMap.ToString().Substring(4);
}

return mappedVolumeName;
}
}
}


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%23GeAwMl...@TK2MSFTNGP05.phx.gbl...

0 new messages