The Application
class in System.Windows.Forms
have a some properties that can be quite useful. For example:
Why are these in in a class in System.Windows.Forms
? What if I wanted to access the CommonAppDataPath
in a console application? Would I have to reference System.Windows.Forms.dll then, or is there an alternative for console applications?
For the paths, you can also look at the Environment
class in .NET:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
and there's a whole slew of "special" folders you can ask for.
The CompanyName and other options are pulled from the "AssemblyInfo.cs" in your "Properties" folder by default - if you have such a file, you can also access those yourself in code.
Hm, with those paths you have to append the company name and product name and such yourself though...
Yes, that's what the System.Windows.Forms assembly is doing for you. If you don't have a Winforms app, you'll have to do that yourself, that's true.
Marc
Information such as "ProductName" comes from the main assembly in a WinForms application. There is no "main" assembly in an ASP.NET application.
If you are running under a service account without a profile (which may often be the case for an ASP.NET app), there will be no UserAppDataPath - in fact attempting to dereference the UserAppDataPath property will throw an exception.
For these reasons, it would not make sense to expose this information to an ASP.NET app.
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