Converting file path.

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi,

Given a file Path, for example "C:\Data\Samples".
How do I convert this to "\\Server\Share\Data\Samples"
The original "C:" , "F:" etc may be local or a mapped network drive.
I am trying to ensure the path (stored as sting in database) is valid from
any machine, regardless of the drive mappings and shares on the machine.

any suggestions,
Tim
 
Hi Tim,

I think that than the best thing you can do is using the directeryinfo and
see if it is in that.

Not checked,

Probably you will have to set that in a try block.

I hope this helps?

Cor
 
* "Tim Marsden said:
Given a file Path, for example "C:\Data\Samples".
How do I convert this to "\\Server\Share\Data\Samples"
The original "C:" , "F:" etc may be local or a mapped network drive.
I am trying to ensure the path (stored as sting in database) is valid from
any machine, regardless of the drive mappings and shares on the machine.

What do you mean with "valid"? Do you want to check if the path exists?
Have a look at the 'System.IO' namespace, 'Directory.Exists'.
 
FYI

I have used a combination of API's WNetGetUniversalName and NetShareEnum.
WNetGetUniversalName gives you the mapped drives, NetShareEnum gives you the
local shared drives. By checking both of these you can establish the UNC
name of a folder or file.

Tim
 
Back
Top