BNG.exe
BNG.exe

Reputation: 25

I want to write a folder path from a textBox to a path specification as string

In my Programm you can select a folder by pressing on a button. The selected folder is written down in a textBox named txtZiel and i want to write this path into the following code to create a logfile.

Creating the log file is alreay workin but i have to write down the path so it is not automatically.

using (var logfile = new System.IO.StreamWriter($@"C:\Users\hmhatd.03\Desktop\Zielordner\{DateTime.Now.ToShortDateString()}.txt"))

I want to replace $@"C:\Users\hmhatd.03\Desktop\Zielordner\ with txtZiel.Text

Upvotes: 0

Views: 121

Answers (1)

Steve
Steve

Reputation: 216273

Better use the Path.Combine to create that name

string fileName = Path.Combine(txtZiel.Text, DateTime.Today.ToString("dd.MM.yyyy") + ".txt");
using (var logfile = new System.IO.StreamWriter(fileName))
{
   ....
}

Notice that I have replaced the output format for DateTime.Today with a format that I am sure will not be problematic for the file system

Upvotes: 1

Related Questions