Fast one, why this code isnt working for me:
Directory.CreateDirectory(DateTime.ToString("dd-MM-yyyy"));
Erorr:
Error 1 An object reference is required for the non-static field, method, or property 'System.DateTime.ToString(string)' Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 83 39 WindowsFormsApplication1
What is wrong? And if I would like to have folders name as "This is folder of" and then add todays date, how should it look?
Maybe you mean:
Directory.CreateDirectory(DateTime.Now.ToString("dd-MM-yyyy"));
What is wrong?
ToString
is an instance method not a static one, therefore you can't call it on DateTime
class directly - you need to call it on an instance of the DateTime
class.
And if I would like to have folders name as "This is folder of" and then add todays date, how should it look?
You can use the Now
/UtcNow
property of the DateTime
class which would give you the current time instance e.g.
DateTime.UtcNow.ToString("dd-MM-yyyy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With