MOSS 2010 linq to SharePoint
2011-09-20 11:02
399 查看
这里主要是介绍一下如何在sharepoint 2010 中使用linq to sharepoint
首先我们新建一个bat执行文件: linq to sharepoint.bat 代码如下:
"%systemdrive%/Program Files/Common Files/Microsoft Shared/web server extensions/14/BIN/spmetal.exe" /web:http://sharepoint02:9003 /code:Entities.cs /language:csharp
pause
这里我解释一下 :
/web 指的是要生成linq的站点,最终生成的代码是这个站点下的所有列表实体类和操作类。
/code 指的是生成的文件名 。
/language 指的是要生成的语言。例如 csharp就代表的是asp.net 的c# 。
关于spmetal.exe的详细用法,请参考 MSDN http://msdn.microsoft.com/en-us/library/ee538255.aspx
OK,我们执行下这个linq to shartepoint.bat文件,如下图所示:
![](http://hi.csdn.net/attachment/201011/2/0_12886708539779.gif)
我们执行这个linq to shartepoint.bat 文件之后,生成的的Entities.cs 是存放在哪呢,
它存放在C:/Windows/System32/Entities.cs
我们把这个文件添加到sharepoint的项目进来,我们打开来看看它是什么样的,如下图所示:
![](http://hi.csdn.net/attachment/201011/2/0_12886708833V3b.gif)
我们发现这里有很多报错的痕迹,主要是因为我们没有引用Microsoft.Sharepoint.Linq.dll导致的。
它的路径地址是:
C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/ISAPI/Microsoft.SharePoint.Linq.dll
我们在项目中创建一个可视化web部件 LinqToSharepointTest
LinqToSharepointTest.ascx 代码如下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="标题" HeaderText="标题" />
<asp:BoundField DataField="Url地址" HeaderText="Url地址" />
<Columns>
<asp:GridView>
LinqToSharepointTest.cs代码如下:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
using Microsoft.SharePoint.Linq;
using Microsoft.SharePoint.WebControls;
namespace SharePointTest.LinqToSharepointTest
{
public partial class LinqToSharepointTestUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string SiteUrl = "http://sharepoint02:9003";
EntitiesDataContext edc = new EntitiesDataContext(SiteUrl);
var query = from sxt in edc.关于深信通
select new
{
sxt.Id,
sxt.标题,
Url地址=SiteUrl+"/Lists/List1/DispForm.aspx?ID="+sxt.Id
};
GridView1.DataSource = query;
GridView1.DataBind();
}
}
}
最后我们把这个webpart添加到该站点进来,效果如下 :
首先我们新建一个bat执行文件: linq to sharepoint.bat 代码如下:
"%systemdrive%/Program Files/Common Files/Microsoft Shared/web server extensions/14/BIN/spmetal.exe" /web:http://sharepoint02:9003 /code:Entities.cs /language:csharp
pause
这里我解释一下 :
/web 指的是要生成linq的站点,最终生成的代码是这个站点下的所有列表实体类和操作类。
/code 指的是生成的文件名 。
/language 指的是要生成的语言。例如 csharp就代表的是asp.net 的c# 。
关于spmetal.exe的详细用法,请参考 MSDN http://msdn.microsoft.com/en-us/library/ee538255.aspx
OK,我们执行下这个linq to shartepoint.bat文件,如下图所示:
![](http://hi.csdn.net/attachment/201011/2/0_12886708539779.gif)
我们执行这个linq to shartepoint.bat 文件之后,生成的的Entities.cs 是存放在哪呢,
它存放在C:/Windows/System32/Entities.cs
我们把这个文件添加到sharepoint的项目进来,我们打开来看看它是什么样的,如下图所示:
![](http://hi.csdn.net/attachment/201011/2/0_12886708833V3b.gif)
我们发现这里有很多报错的痕迹,主要是因为我们没有引用Microsoft.Sharepoint.Linq.dll导致的。
它的路径地址是:
C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/ISAPI/Microsoft.SharePoint.Linq.dll
我们在项目中创建一个可视化web部件 LinqToSharepointTest
LinqToSharepointTest.ascx 代码如下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="标题" HeaderText="标题" />
<asp:BoundField DataField="Url地址" HeaderText="Url地址" />
<Columns>
<asp:GridView>
LinqToSharepointTest.cs代码如下:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
using Microsoft.SharePoint.Linq;
using Microsoft.SharePoint.WebControls;
namespace SharePointTest.LinqToSharepointTest
{
public partial class LinqToSharepointTestUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string SiteUrl = "http://sharepoint02:9003";
EntitiesDataContext edc = new EntitiesDataContext(SiteUrl);
var query = from sxt in edc.关于深信通
select new
{
sxt.Id,
sxt.标题,
Url地址=SiteUrl+"/Lists/List1/DispForm.aspx?ID="+sxt.Id
};
GridView1.DataSource = query;
GridView1.DataBind();
}
}
}
最后我们把这个webpart添加到该站点进来,效果如下 :
|
相关文章推荐
- moss 2010 linq to sharepoint
- MOSS 2010:Visual Studio 2010开发体验(15)——LINQ to SharePoint
- MOSS 2010:Visual Studio 2010开发体验(15)——LINQ to SharePoint
- MOSS 2010:Visual Studio 2010开发体验(15)——LINQ to SharePoint
- SP 2010: Getting started with LINQ to SharePoint in SharePoint 2010
- MOSS SharePoint 2007 SSP migration to SharePoint 2010
- How to Integrate SAP Business Data Into SharePoint 2010 Using Business Connectivity Services and LINQ to SAP
- Sharepoint学习笔记---SPList--使用Linq to Sharepoint间接查询External List(3.使用Linq to Sharepoint查询List内容)
- Upgrade from SharePoint 2010 to SharePoint 2016
- SharePoint 2010 查询不以某个字符开头的数据[How to Create a SharePoint “Does Not Begin With” Filtered List View]---计算栏的妙用
- How to open MS word document from the SharePoint 2010 using Microsoft.Office.Interop.dll
- How to install sharepoint server 2010 sp2 in window 7 x64
- How to remove the ribbon tabs in list forms in SharePoint 2010
- Moss/Sharepoint 2010 如何导出webpart,导出按钮不见了
- Use Microsoft SharePoint Designer 2010 to customize the list view 2
- SharePoint Hosting - 2010, MOSS, WSS, Foundation
- Configure Send To connections in SharePoint 2010
- Linq to sharepoint
- How to install SharePoint 2010 on Windows 7
- How to configure SharePoint 2010 Search to crawl share file servers?