日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MOSS中对列表的一些操作(创建,查询等)

發布時間:2025/3/20 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MOSS中对列表的一些操作(创建,查询等) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原貼地址:www.cnblogs.com/carysun ?? 作者:生魚片
http://tech.ddvip.com/2008-10/122527135586704.html

1.查詢列表的所有字段SPSite site = new SPSite("http://carysun");
SPWeb web=site.OpenWeb();
SPList list = web.GetList("/IT Infrastructure");
foreach (SPField sf in list.Fields)
{
  Console.WriteLine(sf.Title);
}2.使用對象模型創建列表,SPListTemplateType.Announcements指定使用通知內容類型作為模板來創建。 注意一定要調用Update()方法。string listName="AnnouList";          
foreach(SPList currList in web .Lists)
{   
  if(currList.Title.Equals(listName,StringComparison.InvariantCultureIgnoreCase))
  {
   list=currList;
   break;
  }
}
if(list==null)
{
   Guid listID=web.Lists.Add(listName,"New nnouncements",SPListTemplateType.Announcements);
   list=web.Lists[listID];
   list.OnQuickLaunch=true;
   list.Update();
}3.使用對象模型給列表添加item,注意一定要調用Update()方法。SPListItem newItem = null;
newItem = list.Items.Add();
newItem["Title"] = "AnnouItem1";
newItem["Body"] = "The first AnnouItem1 ";
newItem["Expires"] = DateTime.Now + TimeSpan.FromDays(2);
newItem.Update();
newItem = list.Items.Add();
newItem["Title"] = "AnnouItem2";
newItem["Body"] = "The second AnnouItem2.";
newItem["Expires"] = DateTime.Now + TimeSpan.FromDays(5);
newItem.Update();
  4.查詢item的相關信息foreach (SPListItem listItem in list.Items){
   foreach (SPField field in list.Fields)
   {
     if (!field.Hidden && !field.ReadOnlyField)
        Console.WriteLine("{0} = {1}", field.Title, newItem[field.Id]);
    }
}5. 如果你要想得到一個列表的item,你可以通過WebId, ListId, and ID來得到.SPWeb parentWeb = web.Site.OpenWeb(new Guid(row["WebId"].ToString()));
SPList list = parentWeb.Lists[ new Guid(row["ListId"].ToString()) ];
SPListItem item = list.GetItemById((int.Parse(row["ID"].ToString())));6.使用SPQuery來查詢列表中item信息:SPQuery query = new SPQuery();
query.ViewFields = @"<FieldRef Name='Title'/><FieldRef Name='Created'/>";
query.Query = @"<Where>
    <Neq>
     <FieldRef Name='Created' />
     <Value Type='DateTime'>
     <Today /></Value>
    </Neq>
  </Where>";
SPList list = web.Lists["AnnouList"];
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem expiredItem in items)
{
  Console.WriteLine(expiredItem["Title"]);
  Console.WriteLine(expiredItem["Created"]);
}6.1. ViewFields 表示你查詢后要返回的字段6.2. Query表示查詢過濾的表達式,使用CAML語言7. 使用SPSiteDataQuery來查詢列表中item信息SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = @"<Lists ServerTemplate='104' />";
query.ViewFields = @"<FieldRef Name='Title'/><FieldRef Name='Created'/>";
query.Webs = "<Webs Scope='SiteCollection' />";
string queryText =@"<Where>
     <Neq>
      <FieldRef Name='Created' />
      <Value Type='DateTime'>
      <Today /></Value>
     </Neq>
   </Where>";
query.Query = queryText;
DataTable table = web.GetSiteData(query);
foreach (DataRow row in table.Rows)
{
   Console.WriteLine(row["Title"].ToString() + row["Created"].ToString());
}7.1. query.Lists = @"<Lists ServerTemplate='104' />";中104代表通知列表類型7.2 query.Webs = "<Webs Scope='SiteCollection' />";為查詢的范圍。7.3. CAML的基本格式是這樣的:“<Where><operator><operand /><operand /></operator> </Where>”.7.4.使用SPQuery返回的是SPListItemCollection,而SPSiteDataQuery可以從不同的列表或是整個網站集查,實際上是返回了一個ADO.NET DataTable對象。7.5 下表是CAML查詢的一些簡單說明:
元素說明
And 并且
BeginsWith 以某字符串開始的
Contains 包含某字符串
Eq 等于
FieldRef一個字段的引用 (在GroupBy 中使用)
Geq 大于等于
GroupBy 分組
Gt 大于
IsNotNull 非空
IsNull
Leq小于等于
Lt 小于
Neq 不等于
Now當前時間
Or
OrderBy 排序
Today 今天的日期
TodayIso今天的日期(ISO格式)
Where Where子句

轉載于:https://blog.51cto.com/xmuxsp/235236

總結

以上是生活随笔為你收集整理的MOSS中对列表的一些操作(创建,查询等)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。