To get the AppData directory, it's best to use the GetFolderPath
method:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
(must add using System
if not present).
%AppData%
is an environment variable, and they are not automatically expanded anywhere in .NET, although you can explicitly use the Environment.ExpandEnvironmentVariable
method to do so. I would still strongly suggest that you use GetFolderPath
however, because as Johannes R?ssel points out in the comment, %AppData%
may not be set in certain circumstances.
Finally, to create the path as shown in your example:
var fileName = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData), "DateLinks.xml");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…