I've made a button so when I click it, it opens up a directory from which I can create a text file, I click the button, it opens the directory fine, I can name the text file what I want and click save, but then I get an error saying "An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll"
This is my code:
private void createAlgorithmsAndComplexityNotesToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text File|*.txt";
sfd.FileName = "Algorithms And Complexity Lecture Notes";
sfd.Title = "Algorithms And Complexity Lecture Notes";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = sfd.FileName;
StreamWriter write = new StreamWriter(File.Create("C:\\Users\antho\\Desktop\\Folder\\Uni\\Programming and data structures\\Assignment 2\\Modules"));
write.Write(writeFile);
write.Close();
}
}
StreamWriter write = new StreamWriter(File.Create("C:\\Users\antho\\Desktop\\Folder\\Uni\\Programming and data structures\\Assignment 2\\Modules"));"@c:\Users\antho\"+ path when do you ever use the path..meaning creating theFileNamelook at this post for an even easier way to create the filename stackoverflow.com/questions/27823789/…"\\"in your super long file path.. once again you never even create a file because you never tell theFile.Createwhat theFilePath + FileName.txtis..Modules. Maybe there is already an folder existing with that name. Second, you forgot to escape the second backslash in your filenam (the one before antho). I'm not sure whether or not\ais a valid character. But it's definitly not a valid character in a file path,