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

Save a string to a text or cvs file on HoloLens

Hi everyone
I am new to programming and HoloLens development, and I am recently working on an application that requires me to store information in a text, cvs, or xml files on the HoloLens.
I am still looking into Serialization stuff in Unity (since I don't need the read function right now), so I tried to go for an easy path that is to store the data as txt format.
I am able to write a line to the console through Debug.Log (I wrote a function that will return a string) and I what I am trying to do now is to write the line into a txt file. So I guess the two questions I have are:

  1. What is the file path on the HoloLens, am I be able to create a save information to a txt file on HoloLens? And if possible, could someone give me an example how to store it?

  2. Could this file be opened through the whole process? I don't need to modify the file, I just need to add a new line to the file whenever I tap on the button in the application.

Thanks a lot

Answers

  • Options

    @Cozywolf

    Maybe this post will help get you started.

    Windows Holographic User Group Redmond

    WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
    WinHUGR YouTube Channel -- live streamed meetings

  • Options
    JasonJason ✭✭
    edited December 2016

    I'm looking to do the same however whenever the user gazes at an object, I would like timestamps to be created within an Excel or CSV file for when the person gazes at the object and then looks away from the object.

    1. OnGazeEnter - timestamp enter time within the spreadsheet yyyy-mm-dd h:mm am/pm

    2. OnGazeLeave - timestamp exit time within the spreadsheet yyyy-mm-dd h:mm am/pm.

    Thanks

  • Options

    I kind of figured it out through some articles and trial and errors. Here is the code I have, the code will write the file to "User Files\LocalAppData[APP name]\LocalState"

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using System;
    using System.IO;
    using System.Linq;
    
    #if WINDOWS_UWP
    using Windows.Storage;
    using Windows.System;
    using System.Threading.Tasks;
    using Windows.Storage.Streams;
    #endif
    
    public class countIcons : MonoBehaviour
    {
    
        //define filePath
    #if WINDOWS_UWP
        Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
        Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    #endif
    
        //private string saved line;
        private string saveInformation = "";
    
        private static string timeStamp = System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "");
        private static string fileName = timeStamp + ".txt";
    
        //private save counter
        private static bool firstSave = true;
    
        //Hashtable declaration
        private static Dictionary<string, IconProperty> iconCollection = new Dictionary<string, IconProperty>();
    
    #if WINDOWS_UWP
        async void WriteData()
        {
            if (firstSave){
            StorageFile sampleFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
            await FileIO.AppendTextAsync(sampleFile, saveInformation + "\r\n");
            firstSave = false;
            }
        else{
            StorageFile sampleFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
            await FileIO.AppendTextAsync(sampleFile, saveInformation + "\r\n");
        }
        }
    #endif
    
        public void addToCounter(string iconName, IconProperty iconproperty)
        {
            iconCollection[iconName] = iconproperty;
            Debug.Log(iconName);
            iconCollection[iconName].getIconProperty(iconName);
            saveInformation = iconCollection[iconName].iconPropertyOutput(iconName);
    #if WINDOWS_UWP
            WriteData();
    #endif
        }
    }
    
  • Options
    @Cozywolf Thank you very much for sharing your code, that's very helpful. Cheers!
  • Options
    lukaswerzlukaswerz
    edited February 2017

    @Cozywolf

    Hi Cozywolf

    Thank you for sharing your code. Does this code works in a master build too?


    edit: actually I try to run it on a master build in a modified way and get errors. (only on master build....) does someone knows what I m doing wrong?


    using System;
    using System.IO;
    using System.Linq;
    #if WINDOWS_UWP
    using Windows.Storage;
    using Windows.System;
    using System.Threading.Tasks;
    #endif
    public class FileWriter : ILogService
    
    {
        //define filePath
    #if WINDOWS_UWP
        StorageFolder storageFolder =
            ApplicationData.Current.LocalFolder;
    
        private
            Windows.Storage.StorageFile sampleFile;
    #endif
    
        //private string saved line;
        private
            string saveInformation = "";
    
        private static
            string timeStamp = DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "");
    
        private static
            string fileName = timeStamp + ".txt";
    
        //private save counter
        private static
            bool firstSave = true;
    
    
        //Hashtable declaration
    
    #if WINDOWS_UWP
        async
            void WriteData
            ()
        {
            if (firstSave)
            {
                sampleFile =
                    await storageFolder.CreateFileAsync(fileName,
                        CreationCollisionOption.ReplaceExisting);
    
                await FileIO.WriteTextAsync(sampleFile, saveInformation + "\r\n");
                firstSave = false;
            }
            else
            {
                await FileIO.AppendTextAsync(sampleFile, saveInformation + "\r\n");
            }
        }
    #endif
    
        public
            void Write
            (string
                text)
        {
            // Debug.Log(text);
            saveInformation = text;
    #if WINDOWS_UWP
            WriteData();
    #endif
        }
    }
    
Sign In or Register to comment.