Skip to content

Instantly share code, notes, and snippets.

View gautamdsheth's full-sized avatar
:shipit:
Shipping

Gautam Sheth gautamdsheth

:shipit:
Shipping
View GitHub Profile
Web web = context.Site.RootWeb;
List pagesLibrary = context.Web.Lists.GetByTitle("Site Pages");
ListItem item = pagesLibrary.RootFolder.Files.AddTemplateFile("/sites/GautamIIWDevSite/SitePages/mymodernpage2.aspx", TemplateFileType.ClientSidePage).ListItemAllFields;
// Make this page a "modern" page
item["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118";
item["Title"] = "My Modern Page2";
item["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec";
item["PageLayoutType"] = "Article";
string siteUrl = "https://tenantname.sharepoint.com/sites/testsitecollection";
string userName = "user.name@tenantname.com";
string password = "password";
using (ClientContext context = new ClientContext(siteUrl))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
Web web = context.Site.RootWeb;
List pagesLibrary = context.Web.Lists.GetByTitle("Site Pages");
ListItem item = pagesLibrary.RootFolder.Files.AddTemplateFile("/sites/test/SitePages/mymodernpage.aspx", TemplateFileType.ClientSidePage).ListItemAllFields;
// Make this page a "modern" page
item["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118";
item["Title"] = "My Modern Page";
item["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec";
item["PageLayoutType"] = "Article";
Web web = context.Site.RootWeb;
List pagesLibrary = context.Web.Lists.GetByTitle("Site Pages");
ListItem item = pagesLibrary.GetItemById(1);
//custom choice column named Category
//add/update your custom columns here
item["TestChoiceCol"] = "Good-day";
item.Update();
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
getCurrentUserPermission('Custom List');
});
function getCurrentUserPermission(listName)
{
var web,clientContext,currentUser,list;
clientContext = new SP.ClientContext.get_current();
using (var context = new ClientContext("https://sitecollection-url"))
{
Site site = context.Site;
context.Load(site);
context.ExecuteQuery();
Web web = site.RootWeb;
context.Load(web);
context.ExecuteQuery();
public class AuthenticationResponse
{
public string token_type { get; set; }
public string scope { get; set; }
public int expires_in { get; set; }
public int expires_on { get; set; }
public int not_before { get; set; }
public string resource { get; set; }
public string access_token { get; set; }
public string refresh_token { get; set; }
class Program
{
static void Main(string[] args)
{
Task.Run(() => MainAsync());
Console.ReadLine();
}
}
@gautamdsheth
gautamdsheth / CreateCommunicationSite_CSOM.cs
Created November 23, 2017 09:23
Create a communication site in SharePoint Online with CSOM and PnP Core
string siteUrl = "https://tenant.sharepoint.com/sites/test";
string userName = "user.name@tenantname.onmicrosoft.com";
string password = "password";
using (ClientContext context = new ClientContext(siteUrl))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
@gautamdsheth
gautamdsheth / RemoveAppByIdCSOM.cs
Last active November 24, 2017 10:05
Remove app(using app guid) from app catalog using CSOM C# in SharePoint Online
string webUrl = "https://tenant-name.sharepoint.com/sites/appcatalog/";
string username = "user.name@tenantname.onmicrosoft.com";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
var credentials = new SharePointOnlineCredentials(username, secureString);
using (ClientContext ctx = new ClientContext(webUrl))
{