简体   繁体   中英

Substring absolute path from known folder StorageFile

I'm working on a WinRT app that uses a local API.

This API returns me some path that looks like this:

C:Users\GB\Documents\MyDocs\DIVERS\fond.png

As you know, I need to use the StorageFolder and StorageFile to use the files that are in the Documents Folder.

I was wondering if there would be a good way to substitute the "known Folder" path for the path I get from the API. It would look like this:

MyDocs\DIVERS\fond.png

I'd like to do it in a nice way, not using splitting by "Documents" because it could get me in trouble if the user name one of his sub folders Documents.

var yourString = @"C:Users\GB\Documents\MyDocs\DIVERS\fond.png";
string knownFolder = @"C:Users\GB\Documents\";
yourString = yourString.Replace(knownFolder, "");
YourMethod($"{knownFolder}{yourString}");

Keep coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM