Reputation: 79
I have site created in SharePoint online. Changing the title using C# CSOM code updates the title of site and same gets retrieved properly.
But when I visit the site/refresh the site newly changed title is visible but again refreshing the page shows original title.
How this can be fixed.
I also tried changing title using "SetSiteProperties" function from - PnP-Sites-Core/Core/OfficeDevPnP.Core/Extensions/TenantExtensions.cs
The function SetSiteProperties throws exception. The site whose title needs to be changed is siteCollection of type TeamSite. Using CSOM or PnP-core, title change works only for Communication Site. For teamsite tile change is not working. Using CSOM it changes temporary only and with Pnp-core throws exception.
Upvotes: 0
Views: 1031
Reputation: 3625
Update the Site Title Property using SharePoint Online CSOM like this:
static void Main(string[] args)
{
string userName = "[email protected]";
string password = "*************";
var siteurl = "https://zheguo.sharepoint.com/sites/dev";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
using (var clientContext = new ClientContext(siteurl))
{
var onlineCredentials = new SharePointOnlineCredentials(userName, securePassword);
clientContext.Credentials = onlineCredentials;
Web web = clientContext.Web;
clientContext.Load(web, a => a.ServerRelativeUrl);
clientContext.ExecuteQuery();
web.Title = "Website Properties Updated via CSOM";
web.Update();
clientContext.Load(web);
clientContext.ExecuteQuery();
}
}
Need to download install and reference SharePoint Online CSOM here:
SharePoint Online Client Components SDK
Result:
Upvotes: 0