C# SharePoint API ClientContextLoad属性未初始化
我有以下代码(SharePointUpload是我拥有的自定义类,包含Microsoft.SharePoint.Client.File对象): 此方法返回后,我立即访问CheckOutType属性,如下所示:C# SharePoint API ClientContextLoad属性未初始化,c#,sharepoint,C#,Sharepoint,我有以下代码(SharePointUpload是我拥有的自定义类,包含Microsoft.SharePoint.Client.File对象): 此方法返回后,我立即访问CheckOutType属性,如下所示: if (fileUpload.File.CheckOutType != CheckOutType.None) { ... } 我得到了这个错误: Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException: 属
if (fileUpload.File.CheckOutType != CheckOutType.None)
{
...
}
我得到了这个错误:
Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException:
属性或字段尚未初始化。还没有
请求或请求尚未执行。可能需要这样做
明确要求。
在Microsoft.SharePoint.Client.ClientObject.CheckUninitializedProperty(字符串
(名称)
为什么我会犯这个错误?该属性不是按照我在上下文的加载方法中定义的那样初始化的吗?您应该首先加载web上下文
using (ClientContext ctx = ....))
{
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(fileUpload.FullSharepointPath);
clientContext.Load(file, f => f.CheckOutType, f => f.MajorVersion);
clientContext.ExecuteQuery();
}
在访问此属性之前,我修改了代码以加载web对象并执行该查询,但在尝试访问CheckOutType属性时仍然会出现相同的错误
using (ClientContext ctx = ....))
{
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(fileUpload.FullSharepointPath);
clientContext.Load(file, f => f.CheckOutType, f => f.MajorVersion);
clientContext.ExecuteQuery();
}