Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

SharePoint Mapper (SPMapper)

5.00/5 (2 votes)
23 May 2014CPOL1 min read 10.5K  
A SharePoint Server Object Model List Mapper to CRUD

Introduction

The CRUD action is one of the common actions to do with data. SharePoint represents 2 types of Object Model: one is Client Object Model and the other is Server Object Model and you can do CRUD via these models (according to the privilege).

The main target of this tip is announcing the first release of SPMapper. Through this component, you can work with Server Object Model & do CRUD actions as easy as drinking a glass of water.

Homepage of SPMapper and download link.

Update (05/23/2014):

Now available on Nuget:

PM > Install-Package MBS.SharePoint.Mapper

Background

It's better to know the Server Object Model.

Please read the Privacy Policy at first (It's not open source but it's free.)

Using the Code

This component allows you to work with CRUD actions, also works with attachments of a SharePoint list.

This component has an Entity Based Approach to SharePoint list .

This component allows you to work with data easily:

C#
using Seifollahi.SPMapper;
 
public partial class SPMapprTestWebpartUserControl : UserControl
{
        protected void Page_Load(object sender, EventArgs e)
        {
                if (!IsPostBack)
                {
                    SampleMethodForSelectData();
                }
        } 
}

void SampleMethodForSelectData()
 {
   // get the SPWeb object
   var myweb = new Web(SPContext.Current.Web);
    
   // make a Mapper object
   Mapper< MyListEntityClass> myListObject = new Mapper< MyListEntityClass>(myweb);
 
 
   // get all attachments of a listitem with ID = 8
   Attachment item8_attachments = myListObject.SelectAttachment(8);
 
   // get the item with ID 8
   MyListEntityClass item8 = myListObject.Select(8);
 
   // make your SPQuery Object
   SPQuery myQry = new SPQuery{ Query = "..." };
 
   // Select your data as a list of your entity class
   List< MyListEntityClass> result = myListObject.Select(myQry);
 
   gridview1.DataSource = result;
   gridview1.DataBind(); 
 }  

To learn more about how it works and how you should code, please refer to First Version documents.

As a developer, you have the ability to customize your classes. Please read the advanced section in the first version. Also, you can work with attachment.

Points of Interest

This component also has a QueryPaging<T> class that helps you in pagination of SharePoint List Items.

Please read all documentation!

Happy Coding!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)