Looking at the source code of OpenFile reveals the possible point of error
public Stream OpenFile()
{
IntSecurity.FileDialogSaveFile.Demand();
string str = base.FileNamesInternal[0];
if (string.IsNullOrEmpty(str))
{
throw new ArgumentNullException("FileName");
}
Stream stream = null;
new FileIOPermission(FileIOPermissionAccess.AllAccess, IntSecurity.UnsafeGetFullPath(str)).Assert();
try
{
stream = new FileStream(str, FileMode.Create, FileAccess.ReadWrite);
}
finally
{
CodeAccessPermission.RevertAssert();
}
return stream;
}
It seems that the code try to get the base.FileNamesInternal[0];
but if you don't show the dialog or choose a file name to save this internal array is probably empty.
I have tried to read the item at index zero in the property FileNames and I get the same error
string file = saveFileDialog1.FileNames(0) ' Index out of range....
I would like to hear from our WinForms more experienced posters if this is really what it seems