Shashi
Shashi

Reputation: 2898

'System.UnauthorizedAccessException' while reading file from Installed location in metro

I am following steps provided in This link. But i am getting "System.UnauthorizedAccessException" while reading file (text File"); . I tried following solution also but not succeed.

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ewr.txt", UriKind.RelativeOrAbsolute));
 IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

please tell me hoe to solve it.

Upvotes: 0

Views: 1730

Answers (1)

Murtuza Kabul
Murtuza Kabul

Reputation: 6514

Try running the code with administrator rights. Your application is trying to access a location which is by default restricted. Another alternative is to store the file in a place where the logged in user has access i.e. application data folder of user.

Problem is not with your code but the effective access rights of the file. However, you can resolve it with changes in code.

Upvotes: 1

Related Questions