user2855518
user2855518

Reputation: 13

Saving file name as a variable

Is there a way to save a file equal to a variable in Visual C#?

I'm using a program to automate MS Word documents and would like them saved with a generic title + the days date.

The following lines of code do not work.

DateTime Tomorrow = DateTime.Now.AddDays(1);
string OKD; 
OKD = Tomorrow.ToString("MM/dd/yyyy");
document.SaveAs(FileName: @"C:\Users\Me\Desktop\Generic name "+ OKD +".doc");

Upvotes: 1

Views: 1578

Answers (1)

Dave Zych
Dave Zych

Reputation: 21887

It doesn't work because you have / in your file name. Save as a date format that can be used as a filename:

OKD = Tomorrow.ToString("MMddyyyy");
document.SaveAs(FileName: @"C:\Users\Me\Desktop\GenericName" + OKD +".doc");

Upvotes: 7

Related Questions