Get URI for a stored file in StorageFile (WinRT)

喜欢而已 提交于 2019-12-04 13:48:50

问题


I'm building a metro app, and I'm trying to get a Uri of an Image after saving it in the StorageFile, this is my code:

StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("samplefile.dat", CreationCollisionOption.ReplaceExisting);

IRandomAccessStream raStream = await file.OpenAsync(FileAccessMode.ReadWrite);
IOutputStream outStream = raStream.GetOutputStreamAt(0);
DataWriter dw = new DataWriter(outStream);
dw.WriteBytes(img); // I'm saving array of bytes
await outStream.FlushAsync();

I read this article:

and it says I can access the stored files using ms-appdata, so i tried this:

Uri uri = new Uri("ms-appdata:///samplefile.dat", UriKind.Absolute);

but it doesnt work


回答1:


Assuming it is stored in the Local folder, the URI should be

Uri uri = new Uri("ms-appdata:///local/samplefile.dat");

Note the additional "local" in the middle.



来源:https://stackoverflow.com/questions/10511946/get-uri-for-a-stored-file-in-storagefile-winrt

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