ajm113

I tried this fallowing code so it writes in the .bat file, but it does not work. Also how can I get the full file path when I selected a file from the open File dialog

private void OnConfigure(object sender, System.EventArgs e)
{
string path32 = @"Starter1.bat";

if (System.IO.File.Exists(path32))
{

OpenFileDialog openFile1 = new OpenFileDialog();

// Initialize the OpenFileDialog to look for text files:
openFile1.Filter = "Executable Files|*.exe";
openFile1.InitialDirectory = @"C:\";
openFile1.Title = "Select a Executable!";
openFile1.RestoreDirectory = false; //true;

if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{

FileInfo f = new FileInfo("Starter1.bat");
StreamWriter w = f.CreateText();
w.WriteLine("Start".Path);
w.Close();
}

}
else
{
System.Windows.Forms.MessageBox.Show("Can't Find \"Start1.bat\"!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}




Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

Mattias Sjogren

What doesn't work

You get the path with openFile1.FileName






Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

ajm113

Mattias Sjogren wrote:

What doesn't work

You get the path with openFile1.FileName



When I try to write too a batch file nothing is written! I do have it so a error should appear if it can't find it, but nothing is showing up.. So I don't know what to do. I did do a google search, but nothing says you have to do any diffrent coding when writting to a .bat file...

Ok, so it is FileName I was not sure on that one.





Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

SThotakura2

try calling sw.Flush() before calling sw.Close()..




Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

timvw

Actually, why are you displaying an OpenFileDialog, since you're not using it afterwards... (eg: use the filename that the user selected)

I would recommend to use the using statements instead (implicit Dispose/Close) of resources...

Code Snippet

using(StreamWriter w = f.CreateText())
{
w.WriteLine("something");
}







Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

ajm113

I tried both scripts, but they don't work... I even tried .txt docs and they seem not to be effected..

I have the OpenDialog at the biggining so it gets the selected .exe and stores the location and parameters in the file. Then when the user wants to start the game that bat file would be set up. So I can also have it so it changes mode of the window. So it is not fullscreen so the user may continue to edit the script for his map.

Wired thing is that this works perfect in Xp, but it seem not to work in Vista.





Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

nobugz

With the RestoreDirectory member set to False, you'll write the .bat file in the same folder as the .exe. Vista won't allow you to create files in folders like c:\program files or c:\windows unless you have administrator privileges. A good example of UAC keeping you out of trouble, you don't want to write .bat files all over your hard disk. Use Application.UserAppDataPath.





Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

ajm113

Code Snippet

if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FileInfo f = new FileInfo(Application.UserAppDataPath +"Starter1.bat");
using (StreamWriter w = f.CreateText())
{
w.WriteLine("START /MAX" + openFile1.FileName);
}
System.Windows.Forms.MessageBox.Show("The path:\n"+openFile1.FileName+" was written in the .bat file!", "Created");
}

}else{
System.Windows.Forms.MessageBox.Show("Can't Find \"Start1.bat\"!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}



You mean like that I looked here:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.userappdatapath.aspx

I tried my way and it does not work.





Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

nobugz

"It does not work". Did it set your motherboard on fire





Re: .NET Base Class Library Does it differ from writting .text files from .bat files? Also how can I get file path from a OpenDialog?

ajm113

How did you know that

Ok, I am wondering I have the testing files where I want to be writtin in.

MyProject->MyProject->obj->Debug

Since for some reason when I store the files I want to be written where the source files are. Like the .cs. It seems to work, but not. Becuase my own "Can't Find File" shows up. So could that be it