WP8 copy SharedStorge file directly into IsolatedStorage

我只是一个虾纸丫 提交于 2019-12-25 02:41:28

问题


I am developing a Windows Phone 8 application but am having a lot of issues with file access permission exceptions hindering the approval of my application when ever I try accessing files in the "local" folder (this only happens after the application has been signed by the WP store, not when deployed from Visual Studio). To solve this I have moved all file operations to IsolatedStorage and this seems to have fixed the problems.

I only have one problem left though. My application needs to make use of the file extension system to open external files and this seems to involve the file first being copied to the local folder where after I can then manually copy it into IsolatedStorage. I have no problem in implementing this but it seems that a file access permission exception also occurs once the system tries to copy the external file into the local folder.

The only way I think this can be solved is if I can direct the system to directly copy into IsolatedStorage but I cannot figure how to do this or if it is even possible. It seems as if though the SharedStorageAccessManager can only copy into a StorageFolder instance but I have no idea how to create one that is directed into IsolatedStorage, any ideas?

PS. Do you think that the Microsoft system might be signing my application with some incompetent certificate or something because there is not a hint of trouble when I deploy the application from Visual Studio, it only happens when Microsoft tests it or when I install it from the store using the Beta submission method.

Below is a screenshot of the catched exception being displayed in a messagebox upon trying to open a file from an email:

EDIT: Just to make it even clearer, I do NOT need assistance in figuring out the normal practice of using a deep link uri to copy an external file into my application directory. I need help in either copying it directly into isolatedstorage or resolving the file access exception.


回答1:


Listening for a file launch

When your app is launched to handle a particular file type, a deep link URI is used to take the user to your app. Within the URI, the FileTypeAssociation string designates that the source of the URI is a file association and the fileToken parameter contains the file token.

For example, the following code shows a deep link URI from a file association.

/FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f0949a19

Upon launch, map the incoming deep link URI to an app page that can handle the file

// Get the file token from the URI
// (This is easiest done from a UriMapper that you implement based on UriMapperBase)
// ...

// Get the file name.
string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

// You will then use the file name you got to copy it into your local folder with
// See: http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.storage.sharedaccess.sharedstorageaccessmanager.copysharedfileasync(v=vs.105).aspx 

SharedStorageAccessManager.CopySharedFileAsync(...)

I've inline the information on how to do this from MSDN http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987(v=vs.105).aspx

Read that documentation and it should be clear how to use the APIs as well as how to setup your URI mapper.

Good luck :)




回答2:


Ok I figured it out. The "install" directory is actually restricted access but for some reason the Visual Studio signing process leaves the app with enough permissions to access this folder. The correct procedure of determining a relative directory is not to use "Directory.GetCurrentDirectory()" but rather to use "ApplicationData.Current.LocalFolder". Hope this helps!



来源:https://stackoverflow.com/questions/20815144/wp8-copy-sharedstorge-file-directly-into-isolatedstorage

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