Community
Hi Guys,
I am using vb.net and I need to find the directory path that my current or open drawing is located in. I'm not sure how to get this from vb.net. Any help is appreciated. Thanks.
Solved! Go to Solution.
Take a look at
Document.Name
Database.OriginalFileName
<CommandMethod("GetFileName")> _ Sub GetFileName() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor ed.WriteMessage(doc.Name & vbCrLf) ed.WriteMessage(db.OriginalFileName) End Sub
Sorry you want the folder,
Application.GetSystemVariable("DWGPREFIX")
or another way
make sure you Import System.IO
Change previos Post to
<CommandMethod("GetFileName")> _ Sub GetFileName() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor ed.WriteMessage(Path.GetDirectoryName(doc.Name) & vbCrLf) ed.WriteMessage(Path.GetDirectoryName(db.OriginalFileName)) End Sub
Thank you for your post. This is exactly what i was looking for. I have a another question now that I'm seeing the output of this. Is there a way to go up one folder level in the directory path? Or i would have to manually trim the string?
<CommandMethod("GetFileName")> _ Sub GetFileName() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor ed.WriteMessage(Path.GetDirectoryName(doc.Name) & vbCrLf) ed.WriteMessage(Path.GetDirectoryName(db.OriginalFileName) & vbCrLf) Dim fpath As String = Path.GetDirectoryName(doc.Name) While fpath <> Nothing ed.WriteMessage(fpath & vbCrLf) fpath = Path.GetDirectoryName(fpath) End While fpath = doc.Name Dim levels As Integer = ed.GetInteger("Enter number of levels you want" & vbCrLf).Value For i As Integer = 0 To levels fpath = Path.GetDirectoryName(fpath) If fpath = Nothing Then Exit For End If Next ed.WriteMessage(fpath & vbCrLf) End Sub
Can't find what you're looking for? Ask the community or share your knowledge.