Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

I have a problem using StorageApplicationPermissions both to write data and read data

My plan is to write serializable data then read it again. I keep getting the exception error (see the code sequence below) reporting:-

Error: cant' find Folder! I am sure I must be doing something quite basically wrong. Any guidance from more informed developers would be most gratefully received.

    static public string FolderAccessToken { get; set; }
    static public async void SelectFolder()
    {
        try
        {

            var picker = new FolderPicker();
            picker.FileTypeFilter.Add(".xml");
            //picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            var folder = await picker.PickSingleFolderAsync();
            if (folder == null)
            {
                FolderAccessToken = "";
                return;
            }

            // Get the future access token by adding the StorageFolder object to the FutureAccessList, 
            // then save the token for future use (it can be re-used after quitting and re-starting app)
            FolderAccessToken = StorageApplicationPermissions.FutureAccessList.Add(folder);

            if (string.IsNullOrEmpty(FolderAccessToken))
            {
                datagramsocket.message_to_send = "Error: can't create or find token!";
                return;
            }

            // Save the token in the app's roaming settings
            ApplicationData.Current.LocalSettings.Values["DocumentsLibraryAccessToken"] = FolderAccessToken;
        }
        catch (Exception e)
        {
            datagramsocket.message_to_send = "innerexception in SelectFolder()b: " + e.InnerException;
            FolderAccessToken = "";
            return;
        }
        datagramsocket.message_to_send = "token: " + FolderAccessToken;
    }
    static public async  void WriteToXML()
    {
        try
        {
            // Get the user to select the Documents library folder (or a sub-folder),
            // thereby granting you access permissions...
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("FolderAccessToken"))
                FolderAccessToken = (string)ApplicationData.Current.LocalSettings.Values["FolderAccessToken"];
            else
            {
                SelectFolder();
            }
            //check if it is still null or empty!
            if (string.IsNullOrEmpty(FolderAccessToken))
            {
                datagramsocket.message_to_send = "WriteToDocLib Error: can't find Folder!";
                return;
            }

            // Get a StorageFolder object using the DocumentsLibraryAccessToken

            var folder =await  StorageApplicationPermissions.FutureAccessList.GetFolderAsync(FolderAccessToken);

            // Check we still have access
            var accessAllowed = StorageApplicationPermissions.FutureAccessList.CheckAccess(folder);
            if (!accessAllowed)
            {
                SelectFolder();
                if (string.IsNullOrEmpty(FolderAccessToken))
                {
                    datagramsocket.message_to_send = "Error: can't create or find token!";
                    return;
                }
            }
            var subfolder = await folder.GetFolderAsync(foldername);
            SerializeObject(subfolder, xmlfile);
            datagramsocket.message_to_send = "serialized to: " + xmlfile;
        }
        catch(Exception e)
        {
            datagramsocket.message_to_send = "ex in WriteToDocLib: " + e.Message;
        }
    }

These statics just live in a useful class I have developed. The phrase: datagramsocket.message_to_send = ... sends the data to a Broadcast receiver on my PC exaclty the same as in the Windows Universal Samples suite that can be downloaded to check UWP Apps. Fundamentally, I try to check for a valid token already and if one is not available, try to create one.

Comments

Sign In or Register to comment.