Cesivi Server - Basic Operations¶
Home → Documentation → Usage → Basic Operations
This guide covers common CRUD operations with examples in REST, CSOM, and PnP PowerShell.
Table of Contents¶
- Creating Lists and Libraries
- List Item Operations
- File Operations
- Folder Operations
- User and Group Operations
- Working with Fields
Creating Lists and Libraries¶
Create a Custom List¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"__metadata": { "type": "SP.List" },
"Title": "Custom List",
"Description": "My custom list",
"BaseTemplate": 100
}'
CSOM (C#):
using (var context = new ClientContext("http://localhost:5000"))
{
var listCreationInfo = new ListCreationInformation
{
Title = "Custom List",
Description = "My custom list",
TemplateType = (int)ListTemplateType.GenericList
};
var list = context.Web.Lists.Add(listCreationInfo);
context.Load(list);
context.ExecuteQuery();
Console.WriteLine($"Created list: {list.Title} ({list.Id})");
}
PnP PowerShell:
# Connect first
Connect-PnPOnline -Url "http://localhost:5000" -UseWebLogin
# Create list
New-PnPList -Title "Custom List" -Template GenericList -Description "My custom list"
Create a Document Library¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.List" },
"Title": "Documents",
"Description": "Document library",
"BaseTemplate": 101
}'
CSOM (C#):
var listCreationInfo = new ListCreationInformation
{
Title = "Documents",
Description = "Document library",
TemplateType = (int)ListTemplateType.DocumentLibrary
};
var list = context.Web.Lists.Add(listCreationInfo);
context.Load(list);
context.ExecuteQuery();
PnP PowerShell:
New-PnPList -Title "Documents" -Template DocumentLibrary -Description "Document library"
Common List Templates¶
| Template | BaseTemplate | Description |
|---|---|---|
| GenericList | 100 | Custom list |
| DocumentLibrary | 101 | Document library |
| Survey | 102 | Survey |
| Links | 103 | Links list |
| Announcements | 104 | Announcements |
| Contacts | 105 | Contacts |
| Events | 106 | Calendar |
| Tasks | 107 | Tasks |
| DiscussionBoard | 108 | Discussion board |
| PictureLibrary | 109 | Picture library |
| CustomGrid | 120 | Custom list in datasheet view |
List Item Operations¶
Add a List Item¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.Data.CustomListItem" },
"Title": "Item 1",
"Description": "First item"
}'
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var itemCreateInfo = new ListItemCreationInformation();
var newItem = list.AddItem(itemCreateInfo);
newItem["Title"] = "Item 1";
newItem["Description"] = "First item";
newItem.Update();
context.ExecuteQuery();
Console.WriteLine($"Created item ID: {newItem.Id}");
PnP PowerShell:
Add-PnPListItem -List "Custom List" -Values @{
Title = "Item 1"
Description = "First item"
}
Update a List Item¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items(1) \
-H "Content-Type: application/json" \
-H "X-HTTP-Method: MERGE" \
-H "IF-MATCH: *" \
-d '{
"__metadata": { "type": "SP.Data.CustomListItem" },
"Title": "Updated Item"
}'
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var item = list.GetItemById(1);
item["Title"] = "Updated Item";
item.Update();
context.ExecuteQuery();
PnP PowerShell:
Set-PnPListItem -List "Custom List" -Identity 1 -Values @{
Title = "Updated Item"
}
Delete a List Item¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items(1) \
-H "X-HTTP-Method: DELETE" \
-H "IF-MATCH: *"
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var item = list.GetItemById(1);
item.DeleteObject();
context.ExecuteQuery();
PnP PowerShell:
Remove-PnPListItem -List "Custom List" -Identity 1 -Force
Get List Items¶
REST API:
# Get all items
curl http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items
# Get with filtering
curl "http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items?\$filter=Title eq 'Item 1'"
# Get with select and top
curl "http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/items?\$select=Title,Modified&\$top=10"
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(items);
context.ExecuteQuery();
foreach (var item in items)
{
Console.WriteLine($"ID: {item.Id}, Title: {item["Title"]}");
}
PnP PowerShell:
# Get all items
Get-PnPListItem -List "Custom List"
# Get with query
Get-PnPListItem -List "Custom List" -Query "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Item 1</Value></Eq></Where></Query></View>"
# Get specific fields
Get-PnPListItem -List "Custom List" -Fields "Title","Modified"
File Operations¶
Upload a File¶
REST API:
# Upload file
curl -X POST "http://localhost:5000/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files/add(url='document.txt',overwrite=true)" \
-H "Content-Type: application/octet-stream" \
--data-binary @document.txt
# Upload with metadata
curl -X POST "http://localhost:5000/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files/add(url='document.txt',overwrite=true)" \
-H "Content-Type: application/octet-stream" \
--data-binary @document.txt
# Then update metadata
curl -X POST http://localhost:5000/_api/web/GetFileByServerRelativeUrl('/Documents/document.txt')/ListItemAllFields \
-H "Content-Type: application/json" \
-H "X-HTTP-Method: MERGE" \
-H "IF-MATCH: *" \
-d '{ "Title": "My Document" }'
CSOM (C#):
var folder = context.Web.GetFolderByServerRelativeUrl("/Documents");
using (var fileStream = System.IO.File.OpenRead(@"C:\temp\document.txt"))
{
var fileCreationInfo = new FileCreationInformation
{
ContentStream = fileStream,
Url = "document.txt",
Overwrite = true
};
var uploadFile = folder.Files.Add(fileCreationInfo);
context.Load(uploadFile);
context.ExecuteQuery();
// Update metadata
var item = uploadFile.ListItemAllFields;
item["Title"] = "My Document";
item.Update();
context.ExecuteQuery();
}
PnP PowerShell:
# Upload file
Add-PnPFile -Path "C:\temp\document.txt" -Folder "Documents"
# Upload with metadata
Add-PnPFile -Path "C:\temp\document.txt" -Folder "Documents" -Values @{
Title = "My Document"
}
Download a File¶
REST API:
# Download file content
curl http://localhost:5000/_api/web/GetFileByServerRelativeUrl('/Documents/document.txt')/\$value -o document.txt
CSOM (C#):
var file = context.Web.GetFileByServerRelativeUrl("/Documents/document.txt");
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl);
using (var fileStream = System.IO.File.Create(@"C:\temp\downloaded.txt"))
{
fileInfo.Stream.CopyTo(fileStream);
}
PnP PowerShell:
Get-PnPFile -Url "/Documents/document.txt" -Path "C:\temp" -FileName "document.txt" -AsFile
Delete a File¶
REST API:
curl -X POST http://localhost:5000/_api/web/GetFileByServerRelativeUrl('/Documents/document.txt') \
-H "X-HTTP-Method: DELETE" \
-H "IF-MATCH: *"
CSOM (C#):
var file = context.Web.GetFileByServerRelativeUrl("/Documents/document.txt");
file.DeleteObject();
context.ExecuteQuery();
PnP PowerShell:
Remove-PnPFile -ServerRelativeUrl "/Documents/document.txt" -Force
Get File Properties¶
REST API:
# Get file metadata
curl http://localhost:5000/_api/web/GetFileByServerRelativeUrl('/Documents/document.txt')
# Get file with properties
curl "http://localhost:5000/_api/web/GetFileByServerRelativeUrl('/Documents/document.txt')?\$expand=ListItemAllFields"
CSOM (C#):
var file = context.Web.GetFileByServerRelativeUrl("/Documents/document.txt");
context.Load(file);
context.Load(file.ListItemAllFields);
context.ExecuteQuery();
Console.WriteLine($"Name: {file.Name}");
Console.WriteLine($"Size: {file.Length} bytes");
Console.WriteLine($"Title: {file.ListItemAllFields["Title"]}");
PnP PowerShell:
Get-PnPFile -Url "/Documents/document.txt"
Folder Operations¶
Create a Folder¶
REST API:
curl -X POST http://localhost:5000/_api/web/folders \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.Folder" },
"ServerRelativeUrl": "/Documents/Subfolder"
}'
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Documents");
var itemCreateInfo = new ListItemCreationInformation
{
UnderlyingObjectType = FileSystemObjectType.Folder,
LeafName = "Subfolder"
};
var newItem = list.AddItem(itemCreateInfo);
newItem["Title"] = "Subfolder";
newItem.Update();
context.ExecuteQuery();
PnP PowerShell:
Add-PnPFolder -Name "Subfolder" -Folder "Documents"
Get Folder Contents¶
REST API:
# Get files in folder
curl http://localhost:5000/_api/web/GetFolderByServerRelativeUrl('/Documents/Subfolder')/Files
# Get subfolders
curl http://localhost:5000/_api/web/GetFolderByServerRelativeUrl('/Documents/Subfolder')/Folders
CSOM (C#):
var folder = context.Web.GetFolderByServerRelativeUrl("/Documents/Subfolder");
context.Load(folder);
context.Load(folder.Files);
context.Load(folder.Folders);
context.ExecuteQuery();
Console.WriteLine($"Folder: {folder.Name}");
Console.WriteLine($"Files: {folder.Files.Count}");
Console.WriteLine($"Subfolders: {folder.Folders.Count}");
PnP PowerShell:
# Get folder
Get-PnPFolder -Url "/Documents/Subfolder"
# Get folder items (files and folders)
Get-PnPFolderItem -FolderSiteRelativeUrl "Documents/Subfolder"
Delete a Folder¶
REST API:
curl -X POST http://localhost:5000/_api/web/GetFolderByServerRelativeUrl('/Documents/Subfolder') \
-H "X-HTTP-Method: DELETE" \
-H "IF-MATCH: *"
CSOM (C#):
var folder = context.Web.GetFolderByServerRelativeUrl("/Documents/Subfolder");
folder.DeleteObject();
context.ExecuteQuery();
PnP PowerShell:
Remove-PnPFolder -Name "Subfolder" -Folder "Documents" -Force
User and Group Operations¶
Get Current User¶
REST API:
curl http://localhost:5000/_api/web/currentuser
CSOM (C#):
var currentUser = context.Web.CurrentUser;
context.Load(currentUser);
context.ExecuteQuery();
Console.WriteLine($"User: {currentUser.Title} ({currentUser.Email})");
PnP PowerShell:
Get-PnPProperty -ClientObject (Get-PnPWeb) -Property CurrentUser
Get All Users¶
REST API:
curl http://localhost:5000/_api/web/siteusers
CSOM (C#):
var users = context.Web.SiteUsers;
context.Load(users);
context.ExecuteQuery();
foreach (var user in users)
{
Console.WriteLine($"{user.Title} - {user.Email}");
}
PnP PowerShell:
Get-PnPUser
Add a User¶
REST API:
curl -X POST http://localhost:5000/_api/web/siteusers \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.User" },
"LoginName": "i:0#.w|domain\\username"
}'
CSOM (C#):
var userCreationInfo = new UserCreationInformation
{
Email = "user@domain.com",
LoginName = "i:0#.w|domain\\username",
Title = "User Name"
};
var user = context.Web.SiteUsers.Add(userCreationInfo);
context.Load(user);
context.ExecuteQuery();
PnP PowerShell:
New-PnPUser -LoginName "i:0#.w|domain\username"
Get All Groups¶
REST API:
curl http://localhost:5000/_api/web/sitegroups
CSOM (C#):
var groups = context.Web.SiteGroups;
context.Load(groups);
context.ExecuteQuery();
foreach (var group in groups)
{
Console.WriteLine($"{group.Title}: {group.Description}");
}
PnP PowerShell:
Get-PnPGroup
Create a Group¶
REST API:
curl -X POST http://localhost:5000/_api/web/sitegroups \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.Group" },
"Title": "Team Members",
"Description": "Team members group"
}'
CSOM (C#):
var groupCreationInfo = new GroupCreationInformation
{
Title = "Team Members",
Description = "Team members group"
};
var group = context.Web.SiteGroups.Add(groupCreationInfo);
context.Load(group);
context.ExecuteQuery();
PnP PowerShell:
New-PnPGroup -Title "Team Members" -Description "Team members group"
Add User to Group¶
CSOM (C#):
var group = context.Web.SiteGroups.GetByName("Team Members");
var user = context.Web.EnsureUser("i:0#.w|domain\\username");
group.Users.AddUser(user);
context.ExecuteQuery();
PnP PowerShell:
Add-PnPGroupMember -LoginName "i:0#.w|domain\username" -Group "Team Members"
Working with Fields¶
Get List Fields¶
REST API:
curl http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/fields
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var fields = list.Fields;
context.Load(fields);
context.ExecuteQuery();
foreach (var field in fields)
{
Console.WriteLine($"{field.Title} ({field.InternalName}): {field.TypeAsString}");
}
PnP PowerShell:
Get-PnPField -List "Custom List"
Add a Text Field¶
REST API:
curl -X POST http://localhost:5000/_api/web/lists/getbytitle('Custom%20List')/fields \
-H "Content-Type: application/json" \
-d '{
"__metadata": { "type": "SP.Field" },
"FieldTypeKind": 2,
"Title": "Custom Field"
}'
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var fieldXml = "<Field Type='Text' DisplayName='Custom Field' Name='CustomField'/>";
list.Fields.AddFieldAsXml(fieldXml, true, AddFieldOptions.AddFieldInternalNameHint);
context.ExecuteQuery();
PnP PowerShell:
Add-PnPField -List "Custom List" -DisplayName "Custom Field" -InternalName "CustomField" -Type Text
Add a Choice Field¶
CSOM (C#):
var list = context.Web.Lists.GetByTitle("Custom List");
var fieldXml = @"<Field Type='Choice' DisplayName='Status' Name='Status'>
<CHOICES>
<CHOICE>Active</CHOICE>
<CHOICE>Pending</CHOICE>
<CHOICE>Completed</CHOICE>
</CHOICES>
</Field>";
list.Fields.AddFieldAsXml(fieldXml, true, AddFieldOptions.AddFieldInternalNameHint);
context.ExecuteQuery();
PnP PowerShell:
Add-PnPField -List "Custom List" -DisplayName "Status" -InternalName "Status" -Type Choice -Choices @("Active","Pending","Completed")
Complete Example: Create and Populate a List¶
PnP PowerShell (Recommended):
# Connect to server
Connect-PnPOnline -Url "http://localhost:5000" -UseWebLogin
# Create list
New-PnPList -Title "Projects" -Template GenericList -Description "Project tracking"
# Add custom fields
Add-PnPField -List "Projects" -DisplayName "Project Manager" -InternalName "ProjectManager" -Type Text
Add-PnPField -List "Projects" -DisplayName "Status" -InternalName "Status" -Type Choice -Choices @("Planning","In Progress","Completed")
Add-PnPField -List "Projects" -DisplayName "Start Date" -InternalName "StartDate" -Type DateTime
Add-PnPField -List "Projects" -DisplayName "Budget" -InternalName "Budget" -Type Currency
# Add items
Add-PnPListItem -List "Projects" -Values @{
Title = "Project Alpha"
ProjectManager = "John Doe"
Status = "In Progress"
StartDate = "2025-01-01"
Budget = 50000
}
Add-PnPListItem -List "Projects" -Values @{
Title = "Project Beta"
ProjectManager = "Jane Smith"
Status = "Planning"
StartDate = "2025-02-01"
Budget = 75000
}
# Query items
Get-PnPListItem -List "Projects" | Format-Table Title, ProjectManager, Status
Related Documentation¶
- API Reference - Complete API documentation
- Migration Guide - Import data from real SharePoint
- Plugin Guide - Extend functionality with plugins
- Export/Import Guide - Backup and restore data
Navigation: - ← Usage Guide - Documentation Home
Last Updated: 2025-11-15