Posts

Microsoft Modern Authentication - SSO

 In some company, getting application level permissions might be hard to do due to security reason.  Within those environment, setting up a job that runs periodically could be difficult.  One of the way to do it is to make sure your job running account has enough permissions and you have a SPN with enough delegated permissions. The below code show how to use the logged in account to get access token for SharePoint scope. public async Task<string> GetSSOUserAccessToken(Uri spSiteUrl) { var _clientId = ""; var _tenantId = ""; var _scheme = siteUrl.Scheme; var _hostUrl = siteUrl.host; var _scope = "AllSites.FullControl"; string[] _scopes = new string[] {string.Format("{0}://{1}/{2}", _schem, _hostUrl, _scope); var authority = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/", "https://login.microsoftonline.com", _tenantId); try {     IPublicClientApplication app = PublicClientApplicationBuilder.Create(_clientId).WithAu

Azure AI Search filter or search with case insensitive

In case that you have a search index field that was created already and couldn't perform the text normalization to allow default search/filter with case insensitive.  You can have another option if your field is set to searchable. You can use search.ismatch function provided by Azure Cognitive Search to perform a match operation on the specific field. Sample syntax for putting in the SearchOptions will be something like SearchOptions options = new SearchOptions {      Size = 50,      Filter = $"search.ismatch('{url}', 'url', 'simple', 'all')" }; The parameters for ismatch: the actual URL to match the name of the index field 'simple' is specifying t he analyzer to use. The simple analyzer is a basic text analyzer that breaks text into terms based on whitespace and punctuation. 'all' specifies the search mode. The all mode means all of the terms in teh query must match Reference: https://learn.microsoft.com/en-us/azure/searc

Token request failed error when getting app only access token

Recently I started seeing token request failed error in my job and my provider hosted app.   The jobs and provided hosted apps have been working well for a long time and it just suddenly happened.  They always failed at TokenHelper.getAppOnlyAccessToken method. Error info: Type: System.Net.WebException Message: Token request failed. After digging around, it looks like there are a few updates on Microsoft to SharePoint, Azure, and AAD.  You can see more details from here, https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/provider-hosted-app-pha-application-errors-tls-errors-and-401/ba-p/2273611. Essentially, here are the 2 solution depending where is your code located: If you're running your jobs or web applications on a server, you can apply the change to update the TLS and cipher used.  See the details for the TLS/Cipher changes in the link above. If you're hosting the provided hosted app in Azure web app, you can update your code instead.  You can add ServicePo

Office 365 Delve Blog Monitoring Tool

As my current client is trying to migrate to Office 365 environment from SharePoint 2013 on-premise, one of the issues is controlling the Delve personal blog.  As of now, there is no option to turn off the personal blog creation on Office 365.  So, the client wants to find way to monitor it.  That way they can at least know if there are any content they need to be aware and handled. As you might already aware that there is really no way to do any customization on Delve (at least I can't find any way).  So I couldn't find any way to do any real time monitor with remote event receiver or something like that. However, I did find a way to do a schedule monitor with console application.  After doing some research on google, I found this blog (https://en.share-gate.com/blog/office-365-delve-blogs-explained) that explains how the Delve blog works. In summary, the Delve blog posts are save into a personal site collection in Pages library and they are based on Story Page content (

Add ribbon action and item context menu actions to site content type

Image
I haven't done this for a while and I was searching for it for a while and not getting the correct answer.  So, once I found it, I have to put the information in here just to remind myself later if I have to do it again sometime in the future. Below are functions to add ribbon action and context menu action to Document content type on the site collection level.  The actions requires edit list permission to see. For the ribbon, you'll be passing in the command for the ribbon which looks something like: private static void addRibbonActionToContentType(ClientContext clientContext, ContentType ct, string cmd, string actionName, string actionText)         {             // create the ribbon.             UserCustomAction customAction = clientContext.Site.UserCustomActions.Add();             customAction.Name = actionName;             customAction.Location = "CommandUI.Ribbon.ListView";             customAction.CommandUIExtension = cmd;             customAct

Easy SharePoint custom form

One of my colleges sent me this link which I find it very useful for all SharePoint versions and environment.  Yes, it is working for Office 365 too. All you need is a little bit of JavaScript skills and concept, then you can implement it.  The best part is that you likely won't have to do any update to the script and it'll just work. I know I'm going to refer to it later.  And here is the link. http://www.markrackley.net/2013/08/29/easy-custom-layouts-for-default-sharepoint-forms/

SharePoint 2013 Performance Issue - Very slow when updating Enterprise Keywords field

Our SharePoint 2013 environment was behaving very slowly and one of the WFE utilization is crazy high.  It is particularly obvious when publisher is trying to update the Enterprise Keywords field (Managed Metadata field) for French site. After working with MS on troubleshooting, the root cause is identified as Outdated database statistics. Refer to this article for reference: https://support.microsoft.com/en-us/kb/3103194. Basically, we update the database statistics and remove cache following the article to execute the following. -- Update DB Stats EXEC sp_MSforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN' -- Remove all elements from the plan cache DBCC FREEPROCCACHE This should be part of your DB maintenance on regular basis.