public void SPRowLimit()
{
using (SPWeb oWebsite = siteCollection.OpenWeb())
{
SPList oList = oWebsite.Lists["Country List"];
SPQuery oQuery = new SPQuery();
// Select the needed fields
oQuery.ViewFields = "
// Limit the number of rows in the selection
oQuery.RowLimit = 2;
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
Response.Write(Convert.ToString(oListItem[oList.Fields.GetField("Title").InternalName]) + "
");
}
}
}
// Query files inside folder in a document library
public void SPView()
{
using (SPWeb oWebsite = siteCollection.OpenWeb())
{
SPList oList = oWebsite.Lists["Yearly Report"];
SPView oView = oList.Views["All Documents"];
SPQuery oQuery = new SPQuery(oView);
// To explore files inside a folder
oQuery.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection collListItemsAvailable =
oList.GetItems(oQuery);
foreach (SPListItem oListItemAvailable in collListItemsAvailable)
{
Response.Write(oListItemAvailable["Name"] + "
");
}
}
}
// Get Custom List Data using LINQ
public void ListusingLinQ()
{
SPSite site = new SPSite("http://praveenkumar:5555");
SPWeb web = site.OpenWeb();
SPList lstCustomer = web.Lists["Country List"];
var customers = from SPListItem customer in lstCustomer.Items
select customer;
foreach (SPListItem item in customers)
{
Response.Write(item.ID.ToString() + "-" + item["Title"].ToString());
}
}
// Get Multiple Custom List Data using LINQ
public void MultipleListValueusingLinq()
{
SPSite site = new SPSite("http://praveenkumar:5555");
SPWeb web = site.OpenWeb();
SPList lstCustomer = web.Lists["Customers"];
SPList lstorders = web.Lists["Order"];
var customerorders =
from SPListItem customer in lstCustomer.Items
join SPListItem order in lstorders.Items on customer.ID.ToString() equals order["CustomerID"].ToString().Split(new string[] { ";#" }, StringSplitOptions.None)[0]
select new { Title = customer["Title"].ToString(), OrderDate = order["OrderDate"].ToString() };
foreach (var item in customerorders)
{
Response.Write(item.Title + "-" + item.OrderDate);
}
}
No comments:
Post a Comment