Solved

get path without letter drive.

Posted on 2010-08-31
9
504 Views
Last Modified: 2012-05-10
Hello,
is there a method in vb.net that returns a path, passed as argument that , without the letter drive?
0
Comment
Question by:arcross
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33566978
Can you give an example of what you want !
0
 
LVL 8

Author Comment

by:arcross
ID: 33567031
From the path:

c:\test1\test2\test3\file1.txt  id like to get it without the drive letter and filename

\test1\test2\test3\
0
 
LVL 5

Expert Comment

by:talkinsmak
ID: 33567048
So what you are looking for is the UNC path.
This is formatted like this:
\\servername\folder1\folder2\file.txt
Hope that helps.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33567154
try this
 Me.Label1.Text = Application.StartupPath
        Me.Label1.Text = Me.Label1.Text.Replace(Me.Label1.Text.Substring(0, 2), "")
    End Sub
0
 
LVL 1

Expert Comment

by:Jacob_Iedema
ID: 33567167
Assuming then you are not talking about a network path, i'm not aware of a method who will do this. However, you can do something like this:


        Label1.Text = Path.GetDirectoryName("C:\temp\somefile.msi")

        Dim var() As String = Split(Label1.Text, ":")
        Label2.Text = var(1).ToString

label2 gives you "\temp"
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33567188
Try this:

        Dim strFile As String = "c:\test1\test2\test3\file1.txt "
        Dim oFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(strFile)
        Dim strPath As String = oFile.Directory.FullName.Replace(oFile.Directory.Root.ToString, "") & "\"

Open in new window

0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33567216
Oh, need to add the leading \,

        Dim strFile As String = "c:\test1\test2\test3\file1.txt "
        Dim oFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(strFile)
        Dim strPath As String = "\" & oFile.Directory.FullName.Replace(oFile.Directory.Root.ToString, "") & "\"

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33567242
Dim fi As New FileInfo ("C:\Temp\MyFile.txt")
Console.WriteLine (fi.DirectoryName.Tostring.Replace(fi.DirectoryName.Tostring.Substring(0, 2), ""))
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33594046
I think that the solution is provided. Don't forget to close this question !
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question