使用“打开方式...”从“Windows资源管理器”打开.txt文件

时间:2013-11-25 23:56:51

标签: vb.net

如何使用“打开方式...”打开* .txt文件,使用此代码?

Dim FileName As New System.IO.StreamReader(<Filename using Open With...>)
RichTextBox1.Text = FileName.ReadToEnd()
FileName.Close()

获取Open的文件名... 怎么弄?

1 个答案:

答案 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