I need to create a file that has t开发者_如何学JAVAoday's date in the file name. How can I get the date just as 20111110
and no slashes?
DateTime.Now.ToString("yyyyMMdd")
Also, you may not be be aware of System.IO.Path.Combine
. It makes building paths a little cleaner and more foolproof.
Simply use a custom datetime format string.
myDate.ToString("yyyyMMdd");
how about something like this:
System.IO.FileInfo file = new System.IO.FileInfo(File1.PostedFile.FileName);
string fname = file.Name.Remove((file.Name.Length - file.Extension.Length));
fname = fname + Now.ToString("_MMddyyyy_HHmmss") + file.Extension;
This creates the filename with the embedded datetime. Then you can prepend you folder path and pass it to SaveAs.
Try this:
DateTime d = DateTime.Now;
string s = d.ToString("yyyyMMdd");
精彩评论