问题
In a Windows 8 app on Windows 8.1 I use the DisplayName property of StorageFile to get a 'friendly' file name.
In the majority of the cases the result is the name of the file without the extension but sometimes the result is the name of the file with the extension. This second case seems to happen when I create a new folder and immediately create a file in it.
Does anyone know if there is a consistent rule for this behavior?
Thanks!
回答1:
It is a strange but You can create extension method which the result would be frienldy name of this file.
I'd wrote it this way:
public static class StorageFileExtensions
{
public static string ToFrienldyName(this StorageFile file) {
return file.DisplayName.Replace("." + file.FileType, string.Empty);
}
}
来源:https://stackoverflow.com/questions/23118887/winrt-storagefile-displayname-strange-behavior