Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:26:55+00:00 2026-06-16T21:26:55+00:00

I have a Windows 8 Metro style app and I have run into what

  • 0

I have a Windows 8 Metro style app and I have run into what should be a simple thing to accomplish, but am finding it extremely difficult to come up with a solution. As it’s been a week now and I still haven’t found a solution, I am offering a bounty of 300 rep for a working solution.

Scenario:

When I edit a textbox, and click Create New Document, a MessageDialog appears asking if I want to save changes to the existing file before creating a new one. If I click “Yes, save changes” – then the FileSavePicker opens, allowing me to save the file.

The Problem:
When I click “Yes, save changes”, I get an ACCESSDENIED exception. I have set breakpoints but exception details have not revealed any other information.

Notes:
I do not have DocumentsLibrary declaration enabled because in this case that is not a requirement, and when this did not work, I then tried enabling it anyway – and I still got the error.

Also, all pieces of code work perfectly on their own (separate from each other), but when you tie it all together, it falls apart when the FileSavePicker tried to open.

I believe this may be a Threading issue. But I’m not sure.

MessageDialog on MSDN.

The code I have is below:

async private void New_Click(object sender, RoutedEventArgs e)
{
    if (NoteHasChanged)
    {
        // Prompt to save changed before closing the file and creating a new one.
        if (!HasEverBeenSaved)
        {

        MessageDialog dialog = new MessageDialog("Do you want to save this file before creating a new one?",
            "Confirmation");
        dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(this.CommandInvokedHandler)));
        dialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler(this.CommandInvokedHandler)));
        dialog.Commands.Add(new UICommand("Cancel", new UICommandInvokedHandler(this.CommandInvokedHandler)));

        dialog.DefaultCommandIndex = 0;
        dialog.CancelCommandIndex = 2;

        // Show it.
        await dialog.ShowAsync();
    }
    else { }
}
else
{
    // Discard changes and create a new file.
    RESET();
}

}

And the FileSavePicker stuff:

private void CommandInvokedHandler(IUICommand command)
{
    // Display message showing the label of the command that was invoked
    switch (command.Label)
    {
        case "Yes":

            MainPage rootPage = this;
            if (rootPage.EnsureUnsnapped())
            {
                // Yes was chosen. Save the file.
                SaveNewFileAs();
            }
            break;
        case "No":
            RESET(); // Done.
            break;
        default:
            // Not sure what to do, here.
            break;
    }
}

async public void SaveNewFileAs()
{
    try
    {
        FileSavePicker saver = new FileSavePicker();
        saver.SuggestedStartLocation = PickerLocationId.Desktop;
        saver.CommitButtonText = "Save";
        saver.DefaultFileExtension = ".txt";
        saver.FileTypeChoices.Add("Plain Text", new List<String>() { ".txt" });

        saver.SuggestedFileName = noteTitle.Text;

        StorageFile file = await saver.PickSaveFileAsync();
        thisFile = file;

        if (file != null)
        {
            CachedFileManager.DeferUpdates(thisFile);

            await FileIO.WriteTextAsync(thisFile, theNote.Text);

            FileUpdateStatus fus = await CachedFileManager.CompleteUpdatesAsync(thisFile);
            //if (fus == FileUpdateStatus.Complete)
            //    value = true;
            //else
            //    value = false;

        }
        else
        {
            // Operation cancelled.
        }

    }
    catch (Exception exception)
    {
        Debug.WriteLine(exception.InnerException);
    }
}

How can I get this to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:26:56+00:00Added an answer on June 16, 2026 at 9:26 pm

    The problem seems to be that you’re opening a FileSavePicker before the MessageDialog is closed (and before the await dialog.ShowAsync() call is terminated). I am not sure of why this behavior happens, but a workaround can be easily done. I’ll only make an example, it will be up to you to adapt it to your needs and model.

    First, declare an Enum.

    enum SaveChoice
    {
        Undefined,
        Save,
        DoNotSave
    }
    

    Then, create a field/property in your class. Again, this is not the most wise design choice but it works as an example.

    SaveChoice _currentChoice;
    

    Then, modify your CommandInvokeHandler method:

    void CommandInvokedHandler(IUICommand command)
    {
        // Display message showing the label of the command that was invoked
        switch (command.Label)
        {
            case "Yes":
                var rootPage = this;
                if (rootPage.EnsureSnapped())
                    _currentChoice = SaveChoice.Save;
                break;
            case "No":
                _currentChoice = SaveChoice.DoNotSave;
                break;
            default:
                _currentChoice = SaveChoice.Undefined;
                // Not sure what to do, here.
                break;
        }
    }
    

    Finally, edit your New_Click method:

    //Continues from dialog.CancelCommandIndex = 2;
    // Show it.
    await dialog.ShowAsync();
    if (_currentChoice == SaveChoice.Save) SaveNewFileAs();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing a windows 8 metro style app using javascript and I have a
I have two font related questions on Windows 8 metro style app development: is
I intended to create a Windows 8 Style App (Metro), but found out there
I'm developing a Metro-style app (for Windows 8) using C# and XAML. I have
I have just finished a metro style App in Windows Developer Preview (for the
I am building a metro style app for windows 8 and I have a
I have a problem understanding one style definition in Windows 8 metro apps. When
I have a windows 8 metro app that displays data on a live tile
In windows 8 metro style app, how to update live tile while app is
I have the following control in a Windows Metro App: string html = <html><body>test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.