c# save a file from an editor in a specific folder and with a specific name without user interaction (winforms)

hi all,

as the title suggests, im trying to save a richtextform as a file in a specific location with a specfic name without user interaction when they click a button

is this possible and can anyone help me out?

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
No, I don't believe so. You could create it though:
string folder = "C:\\path\\to\\output";
if (!System.IO.Directory.Exists(folder)) System.IO.Directory.CreateDirectory(folder);
System.IO.File.WriteAllText(folder + "\\file.rtf", this.richTextBox1.RTF);

Open in new window

käµfm³d 👽Commented:
I believe what you are asking is:
System.IO.File.WriteAllText("C:\path\to\output\file.rtf", this.richTextBox1.RTF);

Open in new window

awilderbeastAuthor Commented:
if the folder does not exist will it create it?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.