创建DriveItem时“从ReadTimeout获取值时出错”

时间:2017-11-28 20:02:35

标签: c# sharepoint microsoft-graph

我正在尝试使用Microsoft Graph API使用现有DriveItem的内容创建新的SharePoint DriveItem。但是,我在尝试创建DriveItem时收到以下错误。有人可以解释一下原因吗?

编辑:简化以使用手动创建的MemoryStream对象

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);
}

我可以使用以下内容直接上传文件内容,但是我无法在一次调用中在DriveItem中指定更多元数据。

var resultItem = await graphClient.Drives["<driveId>"].Items["<folderId>"].ItemWithPath("00_newDoc.docx").content.Request().PutAsync<DriveItem(docStream);

错误:

  

从'System.IO.MemoryStream'上的'ReadTimeout'获取值时出错。
  at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object   目标)   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter   writer,Object value,JsonContainerContract contract,JsonProperty   成员,JsonProperty财产,JsonContract&amp; memberContract,Object&amp;   memberValue)at   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter   writer,Object value,JsonObjectContract契约,JsonProperty   成员,JsonContainerContract collectionContract,JsonProperty   containerProperty)at   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter   writer,Object value,JsonContract valueContract,JsonProperty成员,   JsonContainerContract containerContract,JsonProperty   containerProperty)at   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter   writer,Object value,JsonObjectContract契约,JsonProperty   成员,JsonContainerContract collectionContract,JsonProperty   containerProperty)at   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter   writer,Object value,JsonContract valueContract,JsonProperty成员,   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   类型,JsonSerializer jsonSerializer)   Microsoft.Graph.Serializer.SerializeObject(Object serializeableObject)   在Microsoft.Graph.BaseRequest.d__36.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)在Microsoft.Graph.BaseRequest.d__32 1.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()   在   Informa.eDocs.AzureFunctions.Functions.PostDocToSharePoint.d__0.MoveNext()

内部例外:

  

此流不支持超时。在   GetReadTimeout(Object)处的System.IO.Stream.get_ReadTimeout()at   Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(对象   目标)

1 个答案:

答案 0 :(得分:0)

我不知道你遇到的问题是什么。

话虽如此,是否有理由下载文件流只是为了再次上传它作为新的driveitem?

您是否考虑过使用复制功能?它应该是这样的(我还没有尝试过):

// Copy item reference
ItemReference iRef = new ItemReference()
{
    DriveId = "b!ez3F6Nysf0yYklsI2gUdcx4e7pSsSDZClwfWe3rFh4mSiYpAIn5zRLcsEeS7g5dr",
    Id = "01YYVWN6F6Y2GOVW7725BZO354PWSELRRZ"
};

// Copy it
await graphClient.Me.Drives["<driveId>"].Items["<ItemId>"].Copy("copiedItem.txt", iRef).Request().PostAsync();

更新

API不打算以这种方式使用。我不知道为什么它不能在一次通话中完成。我知道你必须首先使用POST创建项目(示例显示文件夹,但文档的想法是相同的),然后PUT后续调用中的内容流。