愚老先生的 WSS3.0 Lists服务的使用方法,帮了大忙

本文介绍WSS3.0 List WebService的使用细节,包括如何处理空值和大小写敏感问题,以及如何构造查询来获取列表项。通过示例代码展示了如何创建查询、设置视图字段及选项,并解析返回的XML数据。
Text Field全为空格时: <Eq><FieldRef Name='TextFieldName' /><Value Type='Text'></Value></Eq>
Text Field不含任何字符时:<IsNull><FieldRef Name='TextFieldName' ></FieldRef></IsNull>,上条不成立
Text Field不区分英文大小写,这一点应该主要取决于数据库的语言设置。

User Field格式为: UserID;#UserName,如:16;#Leo Ge
如果某个字段为空,则有可能不返回该字段,对XmlNode的Attribute必须先作有效性检验,如:
if (i.Attributes.GetNamedItem("ows_Machine")!=null) taskItem.Machine = i.Attributes["ows_Machine"].Value;

GetListItems的一般性做法:
XmlDocument xmlDoc  =   new  XmlDocument();
XmlElement query 
=  xmlDoc.CreateElement( " Query " );
XmlElement viewFields 
=  xmlDoc.CreateElement( " ViewFields " );
XmlElement queryOptions 
=  xmlDoc.CreateElement( " QueryOptions " );
query.InnerXml 
=   " <Where> "
                    
+   " <Or> "
                        
+   " <Eq><FieldRef Name='Machine' /><Value Type='Text'> "   +  machineName  +   " </Value></Eq> "
                        
+   " <Or> "
                            
+   " <IsNull><FieldRef Name='Machine'></FieldRef></IsNull> "
                            
+   " <Eq><FieldRef Name='Machine' /><Value Type='Text'></Value></Eq> "
                        
+   " </Or> "
                    
+   " </Or> "
                    
+   " </Where> " ;
viewFields.InnerXml 
=   "" ;
queryOptions.InnerXml 
=   "" ;
XmlNode node 
=  wss.GetListItems( " {E7E1EEC8-F627-48A9-8228-F4BC1CA45F0C} " " {FC3C7DFF-7399-4944-A155-56AF8BCB0F11} " , query, viewFields,  " 100 " , queryOptions,  null );

NameTable nt 
=   new  NameTable();
XmlNamespaceManager xnm 
=   new  XmlNamespaceManager(nt);
xnm.AddNamespace(
" rs " " urn:schemas-microsoft-com:rowset " );
xnm.AddNamespace(
" z " " #RowsetSchema " );

xmlDoc 
=   new  XmlDocument();
xmlDoc.ImportNode(node,
true );

foreach  (XmlNode i  in  node.SelectNodes( " rs:data/z:row " ,xnm))
{
   
int id =int.Parse(i.Attributes["ows_ID"].Value);
   
string title = i.Attributes["ows_Title"].Value;
   
bool reloadData = i.Attributes["ows_Reload_x0020_Data"].Value == "1" ? true : false;
   DateTime created 
= DateTime.Parse(i.Attributes["ows_Created"].Value);
   
string createdBy = i.Attributes["ows_Author"].Value; // 格式为userID;#userName
   DateTime modified = DateTime.Parse(i.Attributes["ows_Modified"].Value);
   
string modifiedBy = i.Attributes["ows_Editor"].Value; // 格式为userID;#userName
   EnumStatus status = (EnumStatus) Enum.Parse(typeof(EnumStatus), i.Attributes["ows_Status"].Value);
  
if (i.Attributes.GetNamedItem("ows_Machine")!=null//可能为空的字段要先作检查
        string machine = i.Attributes["ows_Machine"].Value;
     }

}

转载于:https://www.cnblogs.com/vincedotnet/archive/2007/11/20/965325.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值