onedrive / onedrive-explorer-win Goto Github PK
View Code? Open in Web Editor NEWOneDrive API Explorer sample code for Windows / C#
OneDrive API Explorer sample code for Windows / C#
When trying to call GetItemAsync
on a folder with special chars in the name ($%~&^#) the API returns a "itemNotFound" exception
When I tried to upload a large file more than 100M with the "Upload" -> "Large File" menu option, I get the following error:
OneDrive reported the following error:
code:
message: Exception of type 'OneDrive.ODServerException' was thrown.
{
"error": {
"code": "invalidRequest",
"message": "Invalid API or resource",
"innererror": {
"code": "generalException"
}
}
}
Class ODSerializationException is missing the initialization of JsonData.
Here is the update:
internal ODSerializationException(string message, string jsonData, Exception innerException = null)
: base(message, innerException)
{
JsonData = jsonData;
}
I am calling ViewChangesAsync to get a list of changes, but in the resulting list of items all of the ParentReference.Path fields appear to be null. I can reconstruct the parent path manually by maintaining a dictionary of ParentReference.Id's and their associated paths as I process the list, but is this expected behavior?
Looks like a directory separator character may need to be pre-pended to the uses of item.Name in this function - it is not returning valid paths for me due to this. Thx.
My system is Windows 10 with OneDrive for Business.
Anytime I right-click and Open
the Documents
directory in File Explorer two things happen:
Documents
directory is opened within the same occurrence of Windows Explorer, which is the expected behavior.This issue only started just after I installed OneDrive for Business. I installed OneDrive for Business and synced my OneDrive to my Documents. I did this by right clicking on my Documents
folder, selecting Location
and entering C:\Users\MyUserID\OneDrive - Business\Documents
and hitting OK.
An attempt to replace the content of an existing file item via the "Upload/Replace Selected Item..." menu option in OneDrive API Explorer results in an ODServerException:
{
"error": {
"code":"",
"message":"The request entity's media type 'application/octet-stream' is not supported for this resource."
}
}
When I suppress the explicit ContentType declaration in ODConnection.UploadToUrl()
private async Task<ODItem> UploadToUrl(Stream sourceFileStream, ItemUploadOptions options, long localItemSize, Uri serviceUri)
{
var request = await CreateHttpRequestAsync(serviceUri, ApiConstants.HttpPut);
//request.ContentType = ApiConstants.ContentTypeBinary;
options.ModifyRequest(request);
...
the ODServerException turns into
{
"error": {
"code":"",
"message":"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource."
}
}
I did not find any details on supported media types or any binary/text encoding requirements for file content uploads in the OneDrive API documentation.
Replacing the entire file via the "Upload/New File In Current Folder" menu entry works, though.
Would be really useful if OneDrive sync the associated file attributes such as; hidden and read-only flags (at least these basic ones), and expose it to the API as well.
Currently, if you have a read-only or hidden file on a device, after syncing it loses those attributes on the other (except for the timestamp).
When I try to download a file about 130M in size, the sample eventually throws an exception of "A Task was canceled".
Also, both download and upload files should support cancellation and progress report. Currently, only uploading large file support progress report.
Please add this awesome onedrive API to nugget or provide a compiled dll for people to quickly download and not have to recompile the code every time.
Which call returns an object of ODUserProfile? Why class ODUserProfile in its own namespace of "OneDrive.DataType", while no other class is in that namespace? Thanks!
When you call ODItem.Path(true)
, if the folder has a space in it, the path has %20 instead of the space. However, when we pass in the path to an ODItemReference, we can pass it in without the URL encoding of the space and it works - ideally it should be the same both ways (there should be no encoding) since we cannot compare what we put in with what we get out...
Is it possible to add a sample on how to authenticate with the new OneDrive API for Windows Store App? Thanks!
I can't build it.
I have a VS 2012 Pro. Let me know build process.
Hi,
Great little api.
However, when uploading a large video (360mb) using UploadLargeFileAsync, I get a thrown objectdisposedexception. Reliability is high with smaller files, so not sure what is causing this.
Using Mono on Android 16, with version 1.0 of the portable class library.
Stack trace :
" at System.Net.WebConnection.EndWrite (System.Net.HttpWebRequest request, Boolean throwOnError, IAsyncResult result) [0x00000] in :0 \n at System.Net.WebConnectionStream+c__AnonStorey2.<>m__1 (IAsyncResult r) [0x00000] in :0 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 \n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[System.Net.WebResponse].GetResult () [0x00000] in <filename unknown>:0 \n at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in :0 \n at System.Net.Http.HttpClient+c__async0.MoveNext () [0x00000] in :0 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 \n at System.Runtime.CompilerServices.TaskAwaiter1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in <filename unknown>:0 \n at OneDrive.WrappedHttpClientRequest+<GetResponseAsync>d__3.MoveNext () [0x0003f] in e:\\Work\\onedrive-explorer-win-master\\OneDriveSDK\\Http\\WrappedHttpClient.cs:52 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n at System.Runtime.CompilerServices.TaskAwaiter
1[OneDrive.Http.IHttpResponse].GetResult () [0x00000] in :0 \n at OneDrive.ODConnection+d__4e.MoveNext () [0x001f8] in e:\Work\onedrive-explorer-win-master\OneDriveSDK\ODConnection.cs:344 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 \n at System.Runtime.CompilerServices.TaskAwaiter1[OneDrive.ODDataModel].GetResult () [0x00000] in <filename unknown>:0 \n at OneDrive.LargeFileUploader+<ExecuteUploadFragment>d__a.MoveNext () [0x00090] in e:\\Work\\onedrive-explorer-win-master\\OneDriveSDK\\LargeFileUploader.cs:81 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n at System.Runtime.CompilerServices.TaskAwaiter
1[OneDrive.ODDataModel].GetResult () [0x00000] in :0 \n at OneDrive.LargeFileUploader+d__0.MoveNext () [0x00151] in e:\Work\onedrive-explorer-win-master\OneDriveSDK\LargeFileUploader.cs:49 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 \n at System.Runtime.CompilerServices.TaskAwaiter1[OneDrive.ODItem].GetResult () [0x00000] in <filename unknown>:0 \n at OneDrive.ODConnection+<StartLargeFileTransfer>d__45.MoveNext () [0x00164] in e:\\Work\\onedrive-explorer-win-master\\OneDriveSDK\\ODConnection.cs:328 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n at System.Runtime.CompilerServices.TaskAwaiter
1[OneDrive.ODItem].GetResult () [0x00000] in :0 \n at OneDrive.ODConnection+d__8a.MoveNext () [0x00095] in e:\Work\onedrive-explorer-win-master\OneDriveSDK\ODConnection.public.cs:218 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 \n at System.Runtime.CompilerServices.TaskAwaiter`1[OneDrive.ODItem].GetResult () [0x00000] in :0 \n at Reeson.TimedService+d__b.MoveNext () [0x00844] in c:\Users\Craggs\Desktop\Reeson2\Reeson2\Reeson\TimedService.cs:338 "
I'm trying to Fail when a name conflict occurs, but it's not working - I can run this code as many times as I like and never get an error...
using (FileStream fs = new FileStream("food.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
{
ODItemReference od = new ODItemReference() { Path = "/drive/root:" };
ODItem rf = await cn.PutNewFileToParentItemAsync(od, "food.txt", fs,
new ItemUploadOptions() { NameConflict = NameConflictBehavior.Fail });
ODItem rf3 = await cn.UploadLargeFileAsync(new ODItemReference() { Path = od.Path + "/food.txt" }, fs,
new ItemUploadOptions() { NameConflict = NameConflictBehavior.Fail });
}
Hello, sorry for opening a issue, could not find another way to contact you.
How do I compile the sample, Visual Studio states:
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2718,5): error MSB3323: Unable to find manifest signing certificate in the certificate store.
The project doesn't open in Visual Studio 2013 (which is why I was asking for it to be on nugget)
When uploading a file and specifing the option to Fail on a name conflict this setting seems to be ignored. The already existing file is silently overwritten.
var opt = new ItemUploadOptions() { NameConflict = NameConflictBehavior.Fail };
var result = await Connection.PutNewFileToParentItemAsync(folder.ItemReference(), "upload2", fStr, opt);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.