Welcome to this SharePoint developer tutorial!
Step 1: Set up your environment
To get started with SharePoint development, you’ll need to set up your environment. Here’s what you’ll need:
- A Windows machine (SharePoint is not compatible with Macs)
- Visual Studio (any version will do, but 2017 or later is recommended)
- SharePoint Server (you can use a trial version or an existing installation)
If you don’t have Visual Studio, you can download the community edition for free. If you don’t have SharePoint, you can install it on your machine or access it through an online environment.
Step 2: Create a new project in Visual Studio
Launch Visual Studio and create a new project:
- File > New > Project
- In the “New Project” dialog box, select “SharePoint Solution” under the “Visual C#” section (or “Visual Basic” if you prefer)
- Choose a name for your project and set the location (e.g., C:\MyProjects\MyFirstSPProject)
Step 3: Create a new SharePoint site
To develop for SharePoint, you’ll need to create a new site. Here’s how:
- Open the SharePoint Management Shell (Start > All Programs > Microsoft SharePoint Products > SharePoint Management Shell)
- Run the command “New-SPSite -Url http://localhost:8080 -Template STS#0” (or choose your own URL and template)
Step 4: Create a new list
Let’s create a new list to practice with. Here’s how:
- Open the SharePoint site you created in Step 3
- Click on “Site Actions” > “More Options” > “Create”
- Select “Custom List” and give it a name (e.g., “MyList”)
Step 5: Add columns to your list
Now let’s add some columns to our list:
- Open the list you created in Step 4
- Click on the “Settings” gear icon > “Edit Columns”
- Add two new columns:
- Name: “Title”
- Type: Single Line of Text
- Name: “Description”
- Type: Multi-Line Text
Step 6: Create a new web part
Let’s create a new web part to display our list:
- Open Visual Studio and open the project you created in Step 2
- Right-click on the project > Add > New Item…
- Select “Web Part” under the “SharePoint” section
- Name it something like “MyListWebPart”
Step 7: Configure the web part
In the “MyListWebPart.cs” file, add the following code:
using System;
using Microsoft.SharePoint.WebControls;
namespace MyFirstSPProject.MyListWebPart
{
public class MyListWebPart : WebPart
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Get the list we created earlier
SPWeb web = SPContext.Current.Web;
SPList myList = web.Lists["MyList"];
// Display the list items in a repeater control
Repeater myRepeater = new Repeater();
foreach (SPListItem item in myList.Items)
{
myRepeater.Controls.Add(new LiteralControl(item.Title + ": " + item.Description));
}
}
}
}
Step 8: Deploy and test the web part
Now let’s deploy our web part to SharePoint:
- Open Visual Studio and right-click on your project > Publish…
- Choose the SharePoint site you created earlier as the target
- Click “Publish” to deploy the web part
To test the web part, go to your SharePoint site and navigate to the page where you want to add it. Click on “Page” > “Edit Page” and drag the web part onto the page.
That’s it! You’ve completed this SharePoint developer tutorial. In the next tutorial, we’ll explore more advanced topics like workflow and business connectivity services.