4

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.
  }
}
Nitesh Kothari
  • 890
  • 12
  • 27

1 Answers1

4

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.

Romasz
  • 29,662
  • 13
  • 79
  • 154
  • ok, but is there any way to allow any kind of document, and what is the content type for "pdf" and "excel" files. Thank you so much. @Romasz – Nitesh Kothari Jan 02 '15 at 11:51
  • @NiteshKothari WP8.0 and WP8.1 *Silverlight* have [Restricted file types](http://msdn.microsoft.com/en-us/library/windows/apps/jj207065(v=vs.105).aspx) - you won't be able to associate with them. – Romasz Jan 02 '15 at 11:55