I am trying to create a new SharePoint DriveItem using the content of an existing DriveItem using the Microsoft Graph API. However, I am getting the error below when attempting to create the DriveItem. Can somebody explain why?
Edit: Simplified to use manually-created MemoryStream object
GraphServiceClient graphClient = GraphSDKHelper.GetAuthenticatedClient();
using (var docStream = new MemoryStream(1024))
{
var doc = new DriveItem
{
Content = docStream,
Name = "00_newDoc.docx",
ParentReference = new ItemReference
{
Id = "<folderId"
}
};
var resultItem = await graphClient.Drives["<driveId>"].Items["<folderId>"].Request().CreateAsync(driveItem);
}
I can upload the file content directly with the following, but I then lose the ability to specify more metadata in the DriveItem in a single call.
var resultItem = await graphClient.Drives["<driveId>"].Items["<folderId>"].ItemWithPath("00_newDoc.docx").content.Request().PutAsync<DriveItem(docStream);
Error:
Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'.
at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer) at Microsoft.Graph.Serializer.SerializeObject(Object serializeableObject) at Microsoft.Graph.BaseRequest.d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.BaseRequest.d__321.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.DriveItemRequest.<CreateAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at Informa.eDocs.AzureFunctions.Functions.PostDocToSharePoint.d__0.MoveNext()
Inner Exception:
Timeouts are not supported on this stream. at System.IO.Stream.get_ReadTimeout() at GetReadTimeout(Object ) at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)