Ok, I'm trying to Create A New File that doesn't exist yet. Basically, I want the user to enter the name of the file and then want VB to create and save the file (currently it will be blank until the user goes back in and reopens it and adds data to it later).

I was trying to use the SaveDialog but am getting "Invalid Path Errors". Here's a sample of the code:

for the initial path
-------------------------------------------------
Public Class form1
Inherits System.Windows.Forms.Form
Public Path As String = "C:\Documents and Settings\Joh\My Documents\Visual Studio Projects\Lists\"
-------------------------------------------------
In the actual procedure:
Private Sub mnuMgrNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMgrNew.Click
With saveFD
.DefaultExt = "im2"
.FileName = Path
.Filter = "IM2 Files (*.im2)|*.im2"
.FilterIndex = 1
.InitialDirectory = "C:\Documents and Settings\Joh\My Documents\Visual Studio Projects\Lists\"
.OverwritePrompt = True
.Title = "Create New List"

End With
If saveFD.ShowDialog() = DialogResult.OK Then
Path = saveFD.FileName
Dim objwriter As StreamWriter = New StreamWriter(Path, False)
objwriter.Close()
'objwriter = Nothing

End If

End Sub


Here is a copy of the error I'm receiving:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll

Additional information: C:\Documents and Settings\Joh\My Documents\Visual Studio Projects\Lists\ is an invalid file name.

The file doesn't exist initially, I want to create it and save it. Geez I miss the old VB6 Open #1 as....

I did think of one solution. I could create a dummy blank file to begin with and when the user wants to create a new file, I can use the copy/move/rename operations to create a copy of the dummy file, move it and rename it but that seems like the long way around a more simple procedure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.