My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and ...

Get list data using SharePoint Object Model

Get list data using SharePoint Object Model:

This article explains how you can use the SharePoint Object Model(MOSS 2007) classes like SPSite and SPWeb in C# or Visual Basic code to fetch data from a custom SharePoint list.

This article explains how you can use the SharePoint Object Model(MOSS 2007) classes like SPSite and SPWeb in C# or Visual Basic code to fetch data from a custom SharePoint list.

Problem:
You want to get data on the basis of url (including siteurl+listname) from the custom SharePoint list.

Resolution:
In this scenario, we can use SharePoint Object Model classes to access data from custom SharePoint list.

public static bool CheckListExists(string listName, SPWeb web,ref SPList list)
{
try
{
//---Check list exist or not
if (web.Lists[listName]!=null)
{
list = web.Lists[listName];
return true;
}
return false;
}
catch (ArgumentException ex)
{
return false;
}
catch (Exception ex)
{
return false;

}
}



Above function used to check list exist in the SharePoint site or not.


public static void GetListData(string listUrl)
{
SPList objList = null;
char [] chrSplitter={'/'};
try
{
listUrl = listUrl.TrimEnd(chrSplitter);
string[] arrList = listUrl.Split(chrSplitter);
if (arrList != null && arrList.Length > 0)
{

using (SPSite site = new SPSite(listUrl))
{
using (SPWeb web = site.OpenWeb())
{
if(CheckListExists(SPEncode.UrlDecodeAsUrl(arrList[arrList.Length - 1]),web,ref objList))
{
//Add business logic here
}
}
}
}


}
catch (Exception ex)
{

}
}



Above function used to get data from SharePoint site by passing the url only. The url contain both site url and list name. For example:

From presentation layer, we make a call to GetListData function

string listUrl="http://amitkumarmca04.blogspot.com/sites/mcapassion/Lists/AmitKumar";
GetListData(listUrl);

Comments

Popular posts from this blog

Sitecore GraphQL Queries

Sitecore Experience Manager Cloud (XM Cloud) Building blocks

Configuring Sitecore Next.js Headless SXA Multisite App in a Sitecore Container