4
votes

I am developing Windows Phone 8.1 Silverlight app,

I am trying to Upload document from my SD card but getting this error.

Access is denied. Exception from HRESULT: 0x80070005
System.UnauthorizedAccessException

I have also added Capability "ID_CAP_REMOVABLE_STORAGE" in WMAppManifest file. But didn't work.

See my code below:

private async void UploadDocument()
{
  StorageFolder externalDevices = KnownFolders.RemovableDevices;

  StorageFolder sdCard = (await externalDevices.GetFoldersAsync()).FirstOrDefault();

  if (sdCard != null)
  {
      //An SD card is present and the sdCard variable now contains a reference to it
  }

  else
  {
      // No SD card is present.
  }
}
1
if u are using a static method to access SD card, then avoid it.Gk_999
@Gk_999 what to do and what is the static method? I am really sorry, I have no idea about this issue. Thanks man and please guide me.Nitesh Kothari
I mean, if your above code is in a static method, then avoid it, i.e. create a non-static class, create an object, and then use this method. This 'MIGHT BE' a possible reason for this error, not necessary.Gk_999
@Gk_999 ok, see my edit, I am still getting same kind of error. ThanksNitesh Kothari
@Romasz I have added capability in both manifest files: WMAppmanifest and package.appxmanifest, but do not getting whats going wrong. ThanksNitesh Kothari

1 Answers

4
votes

WP8.1 has also new manifest file - Package.appxmanifest - ensure that you have also added capability there - Location. Also you will have to add file type association as it's Silverlight.

Though (I don't know why) you will have to add this the first time from code - right click on Package.appxmanifest file -> View code and add for example like this in application/Extensions section:

<Extension Category="windows.fileTypeAssociation">
  <FileTypeAssociation Name="text">
    <DisplayName>Text file</DisplayName>
    <SupportedFileTypes>
      <FileType ContentType="text/file">.txt</FileType>
    </SupportedFileTypes>
  </FileTypeAssociation>
</Extension>

Once you add it and save, you be able to add/edit FileTypeAssociations via graphic UI.