c#


No permission to delete / overwrite files in subfolders of ApplicationData.Current.LocalFolder


I am facing an problem with files that I create within my application in dedicated sub folders of ApplicationData.Current.LocalFolder. I can create sub folders with ApplicationData.Current.LocalFolder.CreateFolderAsync() and even place files in it. But as soon as I try to overwrite or delete files, I get an access violation exception. (Read Access is still possible)
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I looked up the UWP pages but most of the time they simply create a new folder and that's it.
My attempt to overwrite the file:
public async Task WriteFileAsync(string filename, Stream fileContent)
{
StorageFolder folder = ApplicationData.Current.LocalFolder;
var deepFolders = filename.Split('/');
if (deepFolders != null)
{
for (var i=0; i<deepFolders.Length - 1; i++)
{
folder = await folder.GetFolderAsync(deepFolders[i]);
}
filename = deepFolders[deepFolders.Length - 1];
}
try
{
StorageFile oldFile = await folder.GetFileAsync(filename);
await oldFile.DeleteAsync();
}
catch (FileNotFoundException) { }
StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
}
The first time it runs just fine, but as soon as the overwrite should take place, I get the exception.
Running the whole stuff without sub-folders works like charm.
The attempt to first read and delete the file resulted in the same exception already during the deletion.

Related Links

Pass value of a StaticResource to ConverterParameter in a combine string
Logging with NLog and runtime parameters to Database
How to build list of failed emails in foreach loop in C#
Inserting Date and time from two text boxes
How to continue page numbering from the highest page number in the previous section?
Remove and modify a selected item from listbox that uses datasource
windows Phone8.1:UI not showing next page because of async await
Token Based Authentication in ASP.NET Core (refreshed)
Not taking to Code behind file in visual studio
Root folder file not getting in App_Code folder
Hide form then show the same form again
Report total summary in XtraReports Devexpress Programmatic?
Parse error with empty date from webservice
Breaking the DateTimePicker by typing in wrong dates
How to to remove characters from numeric value using regex
Migration of database in MVC .net code first approach when connection string is changed on runtime

Categories

HOME
logging
model-view-controller
stata
locale
formatting
spotfire
itext7
salesforce-lightning
pandoc
query-string
sms
glympse
collision-detection
coding-style
spring-data-solr
dynamics-crm-2011
aspectj
adroitlogic
tracking
nsoperation
bookmarklet
internet-explorer-7
windows-phone
android-actionbar
md2
bug-reporting
hololens
pushbullet
email-client
aws-certificate-manager
nsopenpanel
workflow-foundation
angular2-changedetection
hierarchical-data
csproj
dynamics-ax-2012-r3
sphinx4
r-factor
xlib
luhn
node-soap
ilog
tunnel
wunderground
android-geofence
asp.net-webhooks
gstreamer-1.0
pygraphviz
motion
observer-pattern
azure-web-roles
file-descriptor
definition
python-venv
infovis
activeandroid
serverless-architecture
seyren
kendo-scheduler
codesniffer
ios-keyboard-extension
symantec
settext
xcode7.1
geokit
django-taggit
trendline
oryx
fadein
php-gd
biginsights
winforms-interop
vensim
esb-toolkit-2.1
pysvn
mind-manager
vundle
xts
msdropdown
twitter-finagle
nodeunit
dynamic-expresso
mysql2
nsautoreleasepool
auctex
gssapi
report-viewer2010
custom-cursor
event-propagation
diazo
utm
fxcopcmd
p4.net
xslt-grouping
silverlight-2.0
konsole
projectgen

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App