Getting SharePoint BlogPost item via LinQ without SPMetal
My Criteria:
a. Getting SharePoint BlogPost items without generating SPMetal
b. Have a custom column which inherit from SPFieldURL
//Remember to add the following using in your CS file:
/*
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.Services;
using System.Linq;
*/
Here goes the code:
On Page Load Event:
SPList list = SPContext.Current.Web.Lists["Posts"];
//Row: to get the first 20 records:pagination
var items = list.Items.OfType<SPListItem>().Take(Rows).Select(
i => new {
ID = i.ID,
Picture1 =(new SPFieldUrlValue(i["Picture1"].ToString())).Url,
Title = i.Title});
//Bind to a DataList
DtBlogPost.DataSource = items.ToList();
DtBlogPost.DataBind();
There you go, this is very simple code.
a. Getting SharePoint BlogPost items without generating SPMetal
b. Have a custom column which inherit from SPFieldURL
//Remember to add the following using in your CS file:
/*
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.Services;
using System.Linq;
*/
Here goes the code:
On Page Load Event:
SPList list = SPContext.Current.Web.Lists["Posts"];
//Row: to get the first 20 records:pagination
var items = list.Items.OfType<SPListItem>().Take(Rows).Select(
i => new {
ID = i.ID,
Picture1 =(new SPFieldUrlValue(i["Picture1"].ToString())).Url,
Title = i.Title});
//Bind to a DataList
DtBlogPost.DataSource = items.ToList();
DtBlogPost.DataBind();
There you go, this is very simple code.
Comments