Solved

get path without letter drive.

Posted on 2010-08-31
9
509 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 46
Error message when using PrintSocket.Send 7 18
VB.net SQLCommandBuilder Insert New Records From DataGridView 3 25
Code enhancement 4 21
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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