I am trying to create a script that load an excel file from a folder on the hololens. That being said I am having trouble with getting errors for StorageFolder and KnownFolders (I am not the most experienced programmer I am afraid). I am using the namespace Windows.Storage but I am still getting the following errors
Error CS0103 The name ‘KnownFolders’ does not exist in the current context Assembly-CSharp C:\Users\jared.turner\Desktop\Hololens Intro\Assets\Uni-Excel\Plugins\MyExcel.cs 34 Active
Error CS0246 The type or namespace name ‘StorageFolder’ could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\jared.turner\Desktop\Hololens Intro\Assets\Uni-Excel\Plugins\MyExcel.cs 34 Active
Can they not be used under MonoBehaviour?
using UnityEngine;
using System.Collections.Generic;
using System;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.HSSF.Util;
using System.Collections.Generic;
using System.IO;
using Excel;
using Windows.Storage;
using System.Data;
using System.Windows;
using System.Threading.Tasks;
namespace Windows.Storage
{
public class MyExcel : MonoBehaviour
{
private string MySheetName = "Sheet_Test";
public List<string> MyCellArray;
public List<string> MyCellArray02;
public List<string> MyString;
private bool ReadExcelEnable_NPOI = false;
private bool ReadExcelEnable_ExcelDataReader = false;
public async void Test()
{
StorageFolder storageFolder = KnownFolders.CameraRoll;
}
Code that uses WinRT APIs directly must be enclosed in #if ENABLE_WINMD_SUPPORT since Mono doesn’t know about these types. See Unity documentation for details: Unity - Manual: WinRT API in C# scripts for UWP
So in this case you’ll need something like:
using UnityEngine;
public class MyExcel: MonoBehaviour
{
public void Test()
{
#if ENABLE_WINMD_SUPPORT
Windows.Storage.StorageFolder storageFolder = Windows.Storage.KnownFolders.CameraRoll;
#endif
}
}
So I have been trying to figure it out but sadly I am still getting the following error:
DirectoryNotFoundException: FileNotFoundException: Could not find a part of the path
“C;\Data\Users|DefaultAccount\AppData\Local\DevelopmentFiles\Ah-64GearboxVS.Release_Win32.jared.turner\Windoes.Storage.StorageFolderNoseGearBox.xls”
Is this error meaning it is looking for a storage folder called nose gearbox? or is it something else?
If I change the file path to my desktop and try it in the editor it works perfect just never on the hololens.
So that’s not the proper way to use StorageFolder. Instead you call StorageFolder’s methods to find/enumerate files (e.g. GetFilesAsync) which returns StorageFile objects, from you actually open a file stream.
My recommendation is to first learn basic WinRT API usage through the UWP samples on GitHub and then try to implement the functionality in Unity scripts.