locked
How to get the variable stored in ApplicationData from another Page RRS feed

  • Question

  • I am trying to save a variable from Page1 in ApplicationData as follows,

    Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                roamingSettings.Values["userName"] = "avn7Fxcjoxg";

    and want to get the variable value ("userName") from page2. I have tried the following code

    Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                if (roamingSettings.Values.ContainsKey("userName"))

                {

                    ytId = roamingSettings.Values["userName"].ToString();

                }

    But it is not working. Can anyone help me??


    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    Thursday, February 6, 2014 6:22 AM

Answers

  • Thanks Dave and James for your quick replies. I have removed the file from source control and now it's working fine.  

    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    • Marked as answer by Saswas Friday, February 7, 2014 6:20 AM
    Friday, February 7, 2014 6:20 AM

All replies

  • Hi Saswas,

    Works fine on my side by VS2013 with Win8.1 App, I can get userName in my second page.

    Could you try to run the app in another machine or create a blank project only for testing this?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, February 6, 2014 8:06 AM
    Moderator
  • Hi James,

    Thanks for your reply. I have tried all the possible options but nothing is working for me. However I am trying to get the value from OnNavigatedTo method as follows,

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                // Restore values stored in app data.
                Windows.Storage.ApplicationDataContainer roamingSettings1 = Windows.Storage.ApplicationData.Current.RoamingSettings;
    
                if (roamingSettings1.Values.ContainsKey("userName"))
                {
                    string ytId = roamingSettings1.Values["userName"].ToString();
                }
            }

     

     


    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    Thursday, February 6, 2014 9:41 AM
  • this looks good. can you show some code how you save the value?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, February 6, 2014 11:05 AM
  • Same as Dave told, I cannot see any problem from your code. Take a look at RoamingSettings | roamingSettings property.

    I would like to know what is the result of this line: roamingSettings1.Values.ContainsKey("userName")? True or false.

    --James 


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, February 7, 2014 6:03 AM
    Moderator
  • Thanks Dave and James for your quick replies. I have removed the file from source control and now it's working fine.  

    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    • Marked as answer by Saswas Friday, February 7, 2014 6:20 AM
    Friday, February 7, 2014 6:20 AM