I wrote code that requires saving a text file. However, I need to save it for my project root so that anyone can access it, not just me.
The method in question here is:
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e) { try { string fileName = Microsoft.VisualBasic.Interaction.InputBox("Please enter a save file name.", "Save Game"); if (fileName.Equals("")) { MessageBox.Show("Please enter a valid save file name."); } else { fileName = String.Concat(fileName, ".gls"); MessageBox.Show("Saving to " + fileName); System.IO.File.WriteAllText(saveScene.ToString(), AppDomain.CurrentDomain.BaseDirectory + @"\" + fileName); } } catch (Exception f) { System.Diagnostics.Debug.Write(f); } }
Many have told me that using AppDomain.CurrentDomain.BaseDirectory will contain the dynamic location of the application’s storage location. However, when I do this, nothing happens and the file is not created.
Is there any other way to do this, or am I just misusing it?
source share