Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Change the Field Type for a List Column Using CSOM in SharePoint 2013 Online
WhatsApp
Vijai Anand Ramalingam
8y
32.1
k
0
0
25
Blog
Code Snippet
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Security;
using
System.Text;
using
System.Threading.Tasks;
using
Microsoft.SharePoint.Client;
namespace
CSOMOffice365
{
class
Program
{
static
void
Main(
string
[] args)
{
string
userName =
"
[email protected]
"
;
Console.WriteLine(
"Enter your password."
);
SecureString password = GetPassword();
// ClienContext - Get the context for the SharePoint Online Site
// SharePoint site URL - https://c986.sharepoint.com
using
(var clientContext =
new
ClientContext(
"https://c986.sharepoint.com"
))
{
// SharePoint Online Credentials
clientContext.Credentials =
new
SharePointOnlineCredentials(userName, password);
// Get the SharePoint web
Web web = clientContext.Web;
// Get the list by Title
List list = web.Lists.GetByTitle(
"Custom"
);
// Get a specific field by Title (TestCol - Single line of text)
Field field = list.Fields.GetByTitle(
"TestCol"
);
// Update the field type to multi line of text
field.TypeAsString =
"Note"
;
field.Update();
clientContext.Load(field);
// Execute the query to the server
clientContext.ExecuteQuery();
// Display the field name and type
Console.WriteLine(field.Title +
" -- Field Type updated to : "
+ field.TypeAsString);
Console.ReadLine();
}
}
private
static
SecureString GetPassword()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
SecureString securePassword =
new
SecureString();
do
{
info = Console.ReadKey(
true
);
if
(info.Key != ConsoleKey.Enter)
{
securePassword.AppendChar(info.KeyChar);
}
}
while
(info.Key != ConsoleKey.Enter);
return
securePassword;
}
}
}
Output
CSOM
SharePoint 2013 Online
Up Next
How to get all the fields for the specified content type using CSOM in SharePoint 2013
Ebook Download
View all
SharePoint Framework (SPFx) A Developers Guide
Read by 11.1k people
Download Now!
Learn
View all
Membership not found