How to use StreamWriter to create a text file and fill it with information from get;set;?

I am trying to put this information (below) into a text file without having to make a text file first. I managed to get it working by already making a text file and then putting the path to the text file, but I want to use StreamWriter to make a text file and then put my information in it, so my program could work on any computer. I hope that's clear enough, I just cant seem to get StreamWriter to work for me.

 private string timeTravelled; public string TimeTravelled { get { return timeTravelled; } set { timeTravelled = value; StreamWriter writer = new StreamWriter("BookingInfo.txt"); { writer.Write(value.ToString() + Environment.NewLine); writer.Close(); } } } 

by MoultonWarrior via /r/csharp

Leave a Reply