如何使用“打开方式...”打开* .txt文件,使用此代码?
Dim FileName As New System.IO.StreamReader(<Filename using Open With...>)
RichTextBox1.Text = FileName.ReadToEnd()
FileName.Close()
获取Open的文件名... 怎么弄?
答案 0 :(得分:1)
您可以使用CommandLineArgs:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Application.CommandLineArgs.Count > 0 Then
'<FileName from OpenWith...> gets in first Command Args
'Windows Explorer sends FileName to CommandLineArgs(0) value
Dim FileNameOpenWith As String = My.Application.CommandLineArgs(0)
Dim ReaderSystem As New System.IO.StreamReader(FileNameOpenWith)
RichTextBox1.Text = ReaderSystem.ReadToEnd()
ReaderSystem.Close()
End If
End Sub