0
votes

The following error occurred in my project, can anyone tell me how to solve this exception?

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) in windows phone 8.1.

I have this code:

using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read))




        StorageFile file = usertoken ;
        try
        {
            if (file != null)
            {
                using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (DataReader dataReader = new DataReader(readStream))
                    {
                        UInt64 size = readStream.Size;

                        UInt32 numBytesLoaded = await dataReader.LoadAsync((UInt32)size);
                        string fileContent = dataReader.ReadString(numBytesLoaded);
                        return (bool)true;
                        // NotifyUser(String.Format("The following text was read from '{0}' using a stream:{1}{2}", file.Name, Environment.NewLine, fileContent), NotifyType.StatusMessage);

                    }
                }
            }
            else
            {
                return (bool)false;
            }
        }
        catch
        {
            return (bool)false;
        }
1
first question: Are you sure the user running the program have read permission on the file?tster
this code isn't scoped properly within a using block. Best to fix that first.Wim Ombelets
yeah,,bt how to check that permission m not getting,please clerify..GaneshGawali
i fix that using block but again i get same exception..GaneshGawali
How did you get the StorageFile? Where from?yasen

1 Answers

0
votes

You need to add the following permissions as described here:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />