converting a filename to a unc filename

B

Brian

I want to convert a filename to it's equivalent unc filename. First, is there
a C# call that i can use that will do it directly?

If not then I will look at the Directory.FullPath() of a file and detemine
it it has a VolumeSeparatorCharacter in it. If so I will then look at the
DriveInfo for that volume and determine if it is a network drive. If not then
I will replace the volume specifier with a unc name like \\192.168.1.2\c$\...

However, what can I use to translate the the network volume drive into a
sharename that I can use to form the unc name? Is there a method for that
somewhere?

thanks
 
X

xrxst32

I want to convert a filename to it's equivalent unc filename. First, is there
a C# call that i can use that will do it directly?

If not then I will look at the Directory.FullPath() of a file and detemine
it it has a VolumeSeparatorCharacter in it. If so I will then look at the
DriveInfo for that volume and determine if it is a network drive. If not then
I will replace the volume specifier with a unc name like \\192.168.1.2\c$\...

However, what can I use to translate the the network volume drive into a
sharename that I can use to form the unc name? Is there a method for that
somewhere?

thanks

hi,
you may use this code to translate a network drive to the unc name of
the share:

// needs reference to "C:\WINDOWS\system32\scrrun.dll"

using System;
using System.Runtime.InteropServices;

namespace Sharename
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Scripting.FileSystemObject fileSystemObj = null;
Scripting.Drive drive = null;

try
{
fileSystemObj = new Scripting.FileSystemObject();
drive = fileSystemObj.GetDrive("I:");
Console.WriteLine("Share: {0}\n", drive.ShareName);
}
finally
{
if (drive != null)
Marshal.ReleaseComObject(drive);
if (fileSystemObj != null)
Marshal.ReleaseComObject(fileSystemObj);
}
}
}
}

Sorry for the late reply but I'm a little bit behind to read the posts
of this group (something about 5000 unread posts or so).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top