Answered by:
System.UnauthorizedAccessException while calling await App.DataModel.SaveRitualDataAsync();

Question
-
I was trying to enhance the Daily Ritual App of Bob Tabor where i want to multiple select and delete the ritual(s) using List View.
but it is throwing the exception when i try to delete ritual(s) and save to the Json File.
System.UnauthorizedAccessException was unhandled by user code
HResult=-2147024891
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at DailyRitual.DataModel.DataSource.<saveRitualDataAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at DailyRitual.DataModel.DataSource.<SaveRitualDataAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at DailyRitual.MultipleSelectionDelete.<OnNavigatedTo>d__0.MoveNext()
InnerException:
=====The Code====
private void SelectRitual_Click(object sender, RoutedEventArgs e)
{
myListView.SelectionMode = ListViewSelectionMode.Multiple;
myListView.SelectionChanged += myListView_SelectionChanged;
CommandBar bottomCommandBar = this.BottomAppBar as CommandBar;
if (bottomCommandBar != null)
{
// Remove AppBarButton.
bottomCommandBar.PrimaryCommands.Clear();
AppBarButton deleteButton = new AppBarButton();
deleteButton.Icon = new SymbolIcon(Symbol.Delete);
deleteButton.Label = "Delete";
deleteButton.IsEnabled = false;
bottomCommandBar.PrimaryCommands.Insert(0, deleteButton);
}
}
void myListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
CommandBar bottomCommandBar = this.BottomAppBar as CommandBar;
AppBarButton deleteButton = (AppBarButton)bottomCommandBar.PrimaryCommands[0];
if (myListView.SelectedItems.Count() != 0)
{
deleteButton.IsEnabled = true;
deleteButton.Click += deleteButton_Click;
}
else
deleteButton.IsEnabled = false;
//bottomCommandBar.PrimaryCommands.Clear();
//throw new NotImplementedException();
}
private async void deleteButton_Click(object sender, RoutedEventArgs e)
{
myListView.SelectionChanged -= myListView_SelectionChanged;
foreach (var item in myListView.SelectedItems)
{
int count = myListView.SelectedItems.Count();
if(count!=0)
App.DataModel.deleteSelectedRituals(((Ritual)(item)));
}
if(myListView.SelectedItems.Count==0)
{
await App.DataModel.SaveRitualDataAsync();
Frame.Navigate(typeof(MultipleSelectionDelete));
}
}========================
private async Task saveRitualDataAsync()
{
var jsonSerializer = new DataContractJsonSerializer(typeof(ObservableCollection<Ritual>));
using (var stream = await Windows.Storage.ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(fileNAME,
CreationCollisionOption.ReplaceExisting))
{
jsonSerializer.WriteObject(stream, _rituals);
stream.Dispose();
}
}Plz Help.
- Moved by Jack Zhai-MSFTMicrosoft contingent staff Monday, July 6, 2015 11:45 AM Not the VS Debugger issue
Thursday, June 25, 2015 8:20 AM
Answers
-
Might try them over here.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.- Proposed as answer by Mike Laughlin Friday, July 10, 2015 1:59 PM
- Marked as answer by Just Karl Friday, July 17, 2015 9:23 PM
Friday, July 10, 2015 1:37 PM
All replies
-
Hi AviRNS,
Based on your description, it would be not the VS IDE issue, it would be a development issue, to really help you find a more appropriate forum, would you mind letting us know more information about this issue?
Which kind of project did you really create, a web app or others?
Thanks,
Jack
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Sunday, June 28, 2015 2:23 AM -
Might try them over here.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.- Proposed as answer by Mike Laughlin Friday, July 10, 2015 1:59 PM
- Marked as answer by Just Karl Friday, July 17, 2015 9:23 PM
Friday, July 10, 2015 1:37 PM