2
我運行在vb.net.I Windows應用程序在文件夾中的XML文件名爲mail.xml名爲XmlFiles.In default.aspx.vb我必須讓道mail.xml.What代碼我要寫,使其成爲可能?要獲得文件的路徑中的一個項目在VB
我運行在vb.net.I Windows應用程序在文件夾中的XML文件名爲mail.xml名爲XmlFiles.In default.aspx.vb我必須讓道mail.xml.What代碼我要寫,使其成爲可能?要獲得文件的路徑中的一個項目在VB
您可以使用Path類的GetFullPath靜態方法:
Dim fileName As string = "myfile.ext"
Dim path1 As string = "mydir"
Dim path2 As string = "\mydir"
Dim fullPath As string
fullPath = Path.GetFullPath(path1)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
path1, fullPath)
fullPath = Path.GetFullPath(fileName)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
fileName, fullPath)
fullPath = Path.GetFullPath(path2)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
path2, fullPath)
' Output is based on your current directory, except
' in the last case, where it is based on the root drive
' GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
' GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
' GetFullPath('\mydir') returns 'C:\mydir'
例子與MSDN。
的另一種方法是使用FileInfo類(自FileSystemInfo繼承)的fullName屬性,參見下面的用法:
Sub DisplayFileSystemInfoAttributes(ByVal fsi As FileInfo)
' Assume that this entry is a file.
Dim entryType As String = "File"
' Determine if this entry is really a directory.
If fsi.Attributes = FileAttributes.Directory Then
entryType = "Directory"
End If
' Show this entry's type, name, and creation date.
Console.WriteLine("{0} entry {1} was created on {2:D}", _
entryType, **fsi.FullName**, fsi.CreationTime)
End Sub
從MSDN爲好。