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.
How to upload files to hololens programmatically?
I know the Device Portal have a File Explorer tool for uploading files to specified folders.
Now I would like to make a tool, which can automatically do this work for me, is there any way?
I have look up the whole document of the Device Portal API reference for HoloLens, but it seems that there's no File Explorer API.
Best Answers
-
OptionsHoloSheep mod
I haven't tried it myself, but the Device Portal core API for App File Explorer might be of some help.
It does mention HoloLens under the Available Device Families.
Let the rest of us know if you have any success.
HTH.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings5 -
Optionsobmar45 ✭✭
Thanks! I have just successfully upload the file to the target folder.
And the codes provided in Open source C# wrapper for Windows Device Portal REST API also helps a lot.
Here is my code:
`private DevicePortal portal;
void PortalConnect()
{
portal = new DevicePortal(
new DefaultDevicePortalConnection(
"http://127.0.0.1:10080/",
"yourname",
"password"));
portal.UnvalidatedCert += DoCertValidation;
Task connectTask = new Task(
async () =>
{
await portal.ConnectAsync();
Console.WriteLine(portal.ConnectionHttpStatusCode);
});
connectTask.Start();
}private bool DoCertValidation(DevicePortal sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}void UploadSrcFile()
{
Task uploadTask = new Task(
async () =>
{
string filePath = Application.StartupPath + "\test.obj";
Console.WriteLine("filePath = " + filePath);await portal.UploadFileAsync("LocalAppData", "test.obj", "LocalState", "YourDemo_1.0.0.0_x86__xxxxxp76mxafg"); Console.WriteLine("uploading finished!"); }); uploadTask.Start();
}`
I don't know why the code format can not be right displayed in this editor if any one know about this issue, please tell me
8
Answers
@obmar45
I haven't tried it myself, but the Device Portal core API for App File Explorer might be of some help.
It does mention HoloLens under the Available Device Families.
Let the rest of us know if you have any success.
HTH.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings
Thanks! I have just successfully upload the file to the target folder.
And the codes provided in Open source C# wrapper for Windows Device Portal REST API also helps a lot.
Here is my code:
`private DevicePortal portal;
void PortalConnect()
{
portal = new DevicePortal(
new DefaultDevicePortalConnection(
"http://127.0.0.1:10080/",
"yourname",
"password"));
portal.UnvalidatedCert += DoCertValidation;
Task connectTask = new Task(
async () =>
{
await portal.ConnectAsync();
Console.WriteLine(portal.ConnectionHttpStatusCode);
});
connectTask.Start();
}
private bool DoCertValidation(DevicePortal sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
void UploadSrcFile()
{
Task uploadTask = new Task(
async () =>
{
string filePath = Application.StartupPath + "\test.obj";
Console.WriteLine("filePath = " + filePath);
}`
I don't know why the code format can not be right displayed in this editor if any one know about this issue, please tell me
Hi.
Is this working for uploading some files I need to my HoloLens ? instead of getting "Failed to upload file. Error:[object Object]"
@obmar45
I am trying to use your code to upload a file to HoloLens but I don't get it working...
Can you tell me what is written in your using block or post the whole code?
You would help me a lot.
Maybe you should install the "Open source C# wrapper for Windows Device Portal REST API" first , and comprehend my codes, some params need to be replaced by your own.
@obmar45 I followed all the steps in setting up the WindowsDevicePortal wrapper API and managed to connect to my Hololens, check IP status, etc. However, I get an exception thrown when I try to send a simple text file to it using the following code:
Note that I'm just building on the existing UWP sample in the library.
The file test.txt is located in the same directory as my application .exe, but these exceptions are thrown when I try to upload it:
Exception thrown: 'System.NotSupportedException' in System.Runtime.WindowsRuntime.dll
Exception thrown: 'System.NotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.NotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.NotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.NotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.NotSupportedException' in System.Private.CoreLib.dll
An exception of type 'System.NotSupportedException' occurred in System.Private.CoreLib.dll but was not handled in user code
Additional information: NotSupported_CloningNotSupported, GetInputStreamAt
Did you encounter these at all?
Never mind - just got it! Switched to the non-UWP version and everything just worked. I think it has something to do with how untrusted certificates are processed in either one.
I tried it UploadFileAsync method, but always throw this exception "This IRandomAccessStream does not support the GetInputStream method because it requires cloning and this stream does not support cloning."
What could be the problem?
Here is my code
public async Task SaveFiles(string userName, string password, string url, string filePath)
{
try
{
DevicePortal portal = new DevicePortal(new DefaultDevicePortalConnection(url, userName, password));
await portal.ConnectAsync();
The HoloLens Companion v2 released on GitHub and renamed to Windows Mixed Reality Commander
This has functionality to load apps into HoloLens or the Emulator and you can use the source code for your app