Trying to read all text files in a directory and then place the contents into a textbox which its property is listed as multiple lines. However, when using this code, there is an error argument thrown 'value cannot be null. Parameter name: FileName'
Any ideas on how to cure would be great. Thank you.
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mnuFileOpen_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mnuFileOpen.Click, tsOpen.Click[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] openfiledialog1 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OpenFileDialog[/SIZE]
[SIZE=2]OpenFileDialog1.InitialDirectory = {directory}
[/SIZE][SIZE=2]OpenFileDialog1.Title =[/SIZE] [SIZE=2][COLOR=#a31515]"Open a Text File"[/COLOR][/SIZE]
[SIZE=2]OpenFileDialog1.Filter = [COLOR=#a31515]"Text Files|*.txt|All Files|*.*"[/COLOR]
OpenFileDialog1.FileName = [COLOR=#a31515]""[/COLOR]
[COLOR=#0000ff]For[/COLOR] i [COLOR=#0000ff][COLOR=#0000ff]As [/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR] = 0 [COLOR=#0000ff][COLOR=#0000ff]To[/COLOR][/COLOR] OpenFileDialog1.FileNames.Count - 1
[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.IO.Stream[/SIZE]
[/SIZE][SIZE=2] s[/SIZE][SIZE=2]trm = openfiledialog1.OpenFile [COLOR=#800000] 'exception thrown here[/COLOR]
TextBox1.Text = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Join(Environment.NewLine, OpenFileDialog1.FileNames)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]IF Not (strm is Nothing) then
'working code here
end if
[/COLOR][/SIZE]end sub
[/COLOR][/SIZE]
Any ideas on how to cure would be great. Thank you.
Last edited: