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.
}
}
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.