瑞雪年

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: 订阅 订阅 :: 管理 ::
  261 随笔 :: 0 文章 :: 432 评论 :: 0 引用

好吧,我也“今天闲来无事"给dac添加了读取SharePoint List的功能,说白了,就是把SharePoint的List看成数据库的表,这样,就可以把http://moss这样的地址当成数据库连接字符串,把caml语句当成command,像使用真的数据库一样获取数据。

 

代码
SharePointConnection connection = new SharePointConnection("http://moss/Docs");
SharePointCommand command
= connection.CreateCommand() as SharePointCommand;
command.ListUrl
= "/Lists/Contract List";
command.CommandText
= "<Where><Geq><FieldRef Name='Title'/><Value Type='Text'>b</Value></Geq></Where>";
SharePointDataAdapter dataAdapter
= new SharePointDataAdapter();
dataAdapter.SelectCommand
= command;
System.Data.DataTable dataTable
= new System.Data.DataTable();
dataAdapter.Fill(dataTable);
this.dataGridView1.DataSource = dataTable;

 

代码
DataContext dataContext = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
this.dataGridView1.DataSource = dataContext.QueryForDataTable<ContractList>(ContractList._.Title >= "b");

 

代码
DataContext dataContext = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
dataContext.Log
= Console.Out;
List
<Documents> documents = dataContext.QueryForList<Documents>(Documents._.Title == "A");

 

代码
DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
dc.Log
= Console.Out;
var expressionData
= dc.GetExpressionData<_SampleCustomList, SampleCustomList>(SampleCustomList._);
var sc
= from s in expressionData
where s.Title == "a" | s.Title == "b2"
orderby s.Title descending
select s;
foreach (var s in sc)
{
Console.WriteLine(s.Title);
}

 

DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
dc.Log
= Console.Out;
QueryableData
<SampleCustomList> scl = dc.GetQueryableData<SampleCustomList>();
var sc
= from s in scl
where (s.Title == "a" || s.Title.StartsWith("b")) && (s.SingleLineOfText != null)
orderby s.Title, s.SingleLineOfText descending
select s;
foreach (var s in sc)
{
Console.WriteLine(s.Title);
}

 


注:1. “今天闲来无事",纯属剽窃,原创请见:http://www.cnblogs.com/gongji/archive/2010/12/04/1896009.html   

2. 请使用“EntitiesGenerator”,选择从SharePoint导入,生成实体项目。

3. http://dac.codeplex.com

posted on 2010-12-05 22:28 瑞雪年 阅读(...) 评论(...) 编辑 收藏