Mam problem z zapisaniem pliku na karcie sd, podglądając wyjątek otrzymuję komunikat:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Mimo tego, że dostęp jest odblokowany w manifescie, nie generuje się plik.
Metody zapisujące:
private void stopButton_Click(object sender, RoutedEventArgs e)
{
Task returnedTask = ProcessFile(name, temp); //tutaj wyjatek pojawia się po wejściu przy pomocy breakpoint'a
}
private async Task ProcessFile(string name, string content)
{
var sdCard = KnownFolders.RemovableDevices;
var sdCardRoot = (await sdCard.GetFoldersAsync()).OrderBy(eachDir => eachDir.DisplayName).FirstOrDefault();
if (sdCard != null && sdCardRoot != null)
{
var backupFile = await sdCardRoot.CreateFileAsync(name + ".txt", CreationCollisionOption.OpenIfExists);
if (backupFile != null)
{
using (var textStream = await backupFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (var textWriter = new DataWriter(textStream))
{
//...
}
}
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="01072596-8503-4252-9151-12ea5e0a1a3b" Publisher="CN=Paweł" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="39908153-ad84-4003-aa23-504de548ba3b" PhonePublisherId="2f21cbbb-e698-47a1-8231-6b827c8b14d0" />
<Properties>
<DisplayName>AccPhone</DisplayName>
<PublisherDisplayName>Paweł</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.3.1</OSMinVersion>
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="AGHost.exe" EntryPoint="MainPage.xaml">
<m3:VisualElements DisplayName="AccPhone" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="AccPhone" ForegroundText="light" BackgroundColor="#464646">
<m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png">
</m3:DefaultTile>
<m3:SplashScreen Image="Assets\SplashScreen.png" />
</m3:VisualElements>
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="AgHost.BackgroundTask">
<BackgroundTasks>
<Task Type="systemEvent" />
</BackgroundTasks>
</Extension>
<Extension Category="windows.fileTypeAssociation">
<FileTypeAssociation Name=".txt">
<DisplayName>data</DisplayName>
<SupportedFileTypes>
<FileType ContentType="text/plain">.txt</FileType>
</SupportedFileTypes>
</FileTypeAssociation>
</Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="removableStorage" />
</Capabilities>
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>AgHostSvcs.dll</Path>
<ActivatableClass ActivatableClassId="AgHost.BackgroundTask" ThreadingModel="both" />
</InProcessServer>
</Extension>
</Extensions>
</Package>