WinRT StorageFile DisplayName strange behavior

淺唱寂寞╮ 提交于 2019-12-11 01:04:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!