Okay so I have created a script that should open and save text files according to the date which has been selected on a datetimepicker control.

In my Bin\Debug directory I have a text file named "30 December 2007.txt"

and here is my code:

vb Code:
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5.     Dim SR As StreamReader
  6.     Dim SW As StreamWriter
  7.  
  8.     Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  9.         Dim theDatePicked As String = DateTimePicker1.Text & ".txt"
  10.         SR = New StreamReader(theDatePicked)
  11.         TextBox1.Text = SR.ReadToEnd
  12.     End Sub
  13.  
  14.     Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
  15.         Dim theDatePicked As String = DateTimePicker1.Text & ".txt"
  16.         SW = New StreamWriter(theDatePicked)
  17.         SW.Write(TextBox1.Text)
  18.         SW.Flush()
  19.     End Sub
  20.  
  21.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  22.         Dim theDatePicked As String = DateTimePicker1.Text & ".txt"
  23.         SR = New StreamReader(theDatePicked)
  24.         TextBox1.Text = SR.ReadToEnd
  25.     End Sub
  26. End Class

I keep getting this error message when I try to debug it.

An error occurred creating the form. See Exception.InnerException for details. The error is: Could not find file 'C:\Users\Matt's Computer\Documents\Visual Studio 2008\Projects\iDiary\iDiary\bin\Debug\.txt'.