A. vb.net 打開文件夾
System.Windows.Forms.OpenFileDialog
System.Windows.Forms.SaveFileDialog
System.Windows.Forms.FolderBrowserDialog
以上三抄個類均襲能夠很好的解決樓主的需求。
具體的請lz自己查msdn
B. vb.net 打開word,怎麼獲取要打開的文件名
OpenFileDialog1.ShowDialog()
Dim s As String = OpenFileDialog1.FileName
MessageBox.Show(s)
C. 怎樣用vb.net讀取本地.txt文件
imports System.IO
讀取指定文件
'
'讀取指定文本文件
Public Function readtext(ByVal path As String)
If path = "" Then
readtext = "操作失敗!"
Exit Function
End If
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim str As String
str = sr.ReadToEnd.ToString
sr.Close()
fs.Close()
readtext = str
Else
readtext = "操作失敗!"
End If
Catch ex As Exception
readtext = "操作失敗!"
End Try
End Function
'向指定文件寫入數據
Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)
If path = "" Then
writetext = "操作失敗!"
Exit Function
End If
Dim op As FileMode
Select Case opi
Case 1
op = FileMode.Append
Case 2
op = FileMode.Create
Case Else
op = FileMode.Create
End Select
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, op)
Dim sr As New StreamWriter(fs)
sr.WriteLine(msg)
sr.Close()
fs.Close()
writetext = "操作完成!"
Else
writetext = "操作失敗!"
End If
Catch ex As Exception
writetext = "操作失敗!"
End Try
End Function
參考這個吧
'
'vb.net源代碼來自www.c-pet.com
'
D. 如何用vb.net 打開一個既存的txt文檔。
可以調用CMD
方法一:
Shell("cmd.exe/ccallc:新建文本文檔.txt",AppWinStyle.NormalFocus)
缺點:不但會打開文本文件,同時還會顯示一個cmd窗體。
方法二:
需要新建一個bat文件到資源里,輸入start C:新建文本文檔.txt
代碼
shell"bat文件的路徑.bat"
這樣就好了,兩種方法各有好壞。一個會顯示cmd窗體,一個需要bat文件。