-5

I am creating an app in Visual Studio 2010 using C# just to generate a string which contains data entered manually when that app runs. I have given a create button to generate that text file. How can make that text file to be created at the place where that app exe file is kept? Its is getting generated in C:\ as given by in in the code.

Gh0sT
  • 317
  • 5
  • 16

1 Answers1

1

The folder where the executable resides is:

string executableLocation = System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().Location);

And so you want to save your file to:

System.IO.Path.Combine(executableLocation, "myfile.txt");
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • string executableLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); System.IO.Path.Combine(executableLocation, "MyFile.txt"); System.IO.File.WriteAllText(?????????, MyString); What should i put here at the place of ?????? to get MyString written in that MyFile.txt? – Gh0sT Apr 24 '13 at 18:35
  • Replace your `?????` with `System.IO.Path.Combine(executableLocation, "MyFile.txt")` – David Heffernan Apr 24 '13 at 18:48