0

I have am iterating through a list of SharePoint list items . A couple of items do not have data so throw the null exception.

I used

 if (!string.IsNullOrEmpty(xt["ows_LinkTitle"].ToString()))
    {
       Entity.DefectType = xt["ows_LinkTitle"].ToString();    
    }

but an error still occurs.

I also tried

if(xt["ows_LinkTitle"].ToString()!= null)
   {
       Entity.DefectType = xt["ows_LinkTitle"].ToString();
   }

I could put a try catch block around it but I don't want to do it for each and every line.

Is there any way to check the sharepoint item value without throwing an error.

4

1 回答 1

1

尝试使用显式转换:

Entity.DefectType = (string)xt["ows_LinkTitle"]; 

null如果您想在分配值之前检查 a

if(xt["ows_LinkTitle"] != null)

as .ToString()on anull是异常的原因。

于 2013-04-10T15:21:41.017 回答