How do I remove version number from file path? - Winforms c#
c#, filepath, winforms
Solution
Use Directory.GetParent method for this purpose.
get
{
var dir = Directory.GetParent(Application.UserAppDataPath);
return Path.Combine(dir.FullName, "FileName.xml");
}
Also note that I've used Path.Combine instead of concatenating paths, this method helps you to avoid so many problems. Never concatenate strings to create path.
Problem
I am wondering how to remove the version number from a file path in a Windows Form Application. Currently I wish to save some users application data to a .xml file located in the roaming user profile settings. To do this I use: ``` get { return Application.UserAppDataPath + "\\FileName.xml"; } ``` However this returns the following string: `C:\Users\user\AppData\Roaming\folder\subfolder\1.0.0.0\FileName.xml` and I was wondering if there is a non-hack way to remove the version number from the file path so the file path looks like this: `C:\Users\user\AppData\Roaming\folder\subfolder\FileName.xml` Besides parsing the string looking for the last "\", I do not know what to do. Thanks