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 c...

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 Stor...

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;           ...

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.

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365

I was looking for how to add custom spell check dictionary in SharePoint 2013 and I found this blog that describes it, http://softlanding.ca/blog/adding-words-to-the-sharepoint-spell-checker-dictionary-(sharepoint-2013-2010). Here is the summary steps in case the above link doesn't work any more. At the root level of your site create a document library called " Spelling " (make sure to name the document library exactly as listed here) On your desktop create a new text file called " Custom Dictionary ", so that the file name looks like " Custom Dictionary.txt " (make sure to spell the file name exactly as listed here) Open the " Custom Dictionary " text file and in this file type in the words you would like NOT to be considered misspelled words (please note that the words are case sensitive so I would have a separate entry for Softlanding and softlanding, and also please make sure each word is listed on a new line) Upload the " C...

SharePoint 2013 REST API Query Items with cross site lookup column

Recently, I had to query items using SharePoint 2013 Rest API (/api/web/lists/getbytitle('')/items).  The problem that makes it hard is that it has a lookup column (Product) that looks up the items in a list from another web.  The typical $filter statement (/_api/web/lists/getbytitle('Pages')/items?$select=Title,Id&$filter=Product eq 1) doesn't work. After searching online and a few trial/error, I got it working by using /_api/web/lists/getbytitle('Pages')/items?$select=Title,Id,ProductId&$filter=Product eq 1 The ProductId field is automatically added to the list by SharePoint when you have a lookup field.  You have to $select that ProductId and then you can filter the Product field.  It's weird but it works.

SharePoint 2013 Client Side Rendering

I was looking for ways to add a custom field type using SharePoint app approach.  I found the following two good article that explain how it can be done.  With the app model, the custom field type control is just not possible any more. So, this is the way. http://blogs.technet.com/b/sharepointdevelopersupport/archive/2013/04/09/how-to-add-a-custom-field-to-blog-posts-in-sharepoint-2013.aspx http://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a Client side rendering actually helps to easily change how a list renders its items as well.  All this technique should work for Office 365 or SharePoint online.

SharePoint 2013 and Visual Studio 2015

If you want to setup a SharePoint 2013 development environment with Visual Studio 2015.  It will be mandatory to install and setup your SharePoint 2013 first then install visual studio 2015.  VS 2015 install .NET 4.6 and it will cause issue when installing SharePoint 2013.  As SharePoint 2013 is looking for .NET 4.5 (probably hardcoded somewhere) and when it can't find it, it can't be installed. You can refer to this blog for more information. http://geekswithblogs.net/bjackett/archive/2015/07/28/be-careful-installing-.net-4.6--visual-studio-2015-with.aspx I found out the hard way and it took me a while to uninstall Visual Studio 2015 and uninstall .NET 4.6 before I can successfully install SharePoint 2013. So be aware, the order matters!!!!

SharePoint 2013 Custom web part with rich text box that triggers SharePoint ribbon

I was creating a web part form which needs to have a rich text editor text box.  The SharePoint 2013 ribbon style works well and looks good.  So, I was looking to utilize it.  To keep the story short, I found the solution in a post, http://sharepoint.stackexchange.com/questions/64698/rich-text-editor-ribbon-based-in-a-webpart-in-sharepoint-2013. In case the link disappeared later, I copied the solution below. ASPX / ASCX: id = "editor" > id = "RTEDiv" tabindex = "0" > ID = "RTEDivHidden" runat = "server" /> class = "commands" > ID = "btnSubmit" Text = "Отправить" runat = "server" CssClass = "editorbtn" /> type = "button" value = "Отмена" id = "btnCancel" class = "editorbtn" /> Simple div container, future rich text div  id="RTEDiv" , hidden field to ...

SharePoint 2013 Using Publishing Page as custom forms for content type

I wanted to customize the display, edit, and new form for a custom list.  I took the approach of using a publishing web with custom web part.  The 2 methods that I use to accomplish that are as follow public static void AddWebParts(SPWeb web, string pageUrl, List webParts)         {             using (SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))             {                                 foreach (WebPart webPart in webParts)                 {                     wpManager.AddWebPart(webPart, webPart.ZoneID, 0);                     wpManager.SaveChanges(webPart);     ...

SharePoint 2013 Using relative path in SharePoint master page

There is a few things that you can do if you want to use relative path for referencing an image or file. 1. You can place your images physically in the 15 hive folder under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\IMAGES (or Layouts location) Place a image here (logo.png) and you can access this image in your masterpage like this 2. Use img tag and you need add  runat="server"  attribute in this tag. <img src=" < % $SPUrl:~SiteCollection/Style%Library/Images/logo.png% > " alt="My Image" runat="server"/> 3. Use this: < a href=' < SharePoint:EncodedLiteral runat="server" text=" < %$SPUrl:~SiteCollection/% > " EncodeMethod="HtmlEncode"/ > ' class="logo" >   < img src='<SharePoint:EncodedLiteral runat="server" text=" < %$SPUrl:~SiteCollection/Style Library/CustomStyle/Images/logo.png%...

SharePoint 2013 Search Conversation Result Source

If you're wondering exactly what types of data the Out-Of-The-Box (OOTB) Conversation result source actually returns, here are some information that I gather by performing some simple test. The result source ID for Conversations is 459dd1b7-216f-4386-9709-287d5d22f568. It returns the following types of content Personal Newsfeed posts and replies Newsfeed activity posts are also returned which could it a pain. Activity feed is the post that tells people you posted something on a community site. Discussion board posts and replies from community sites Site feed posts and replies from community and team sites (and probably all sites that enable site feed feature)

SharePoint 2013 - Use JSLink to Create Custom Field Type

Image
One of the things that we used to be able to do with server farm solution is to create custom field type and custom field type control.  With the App Model approach, we'll need an alternative way to give us the custom form that we need. SharePoint is using JSLink for a lot of displaying option.  You can specify a JavaScript to be used in a  web part or for a field.  The example below shows how you can create custom displaying field.  The example do the following: It customize the displaying of the Is Separator field to add onclick event handling if the URL field is the default value, it sets the default value for both the URL and the description text box Sample form Below is the JavaScript sample code and I saved it in isSeparator.js //IsSeparator Display (function () {     // Create object that have the context information about the field that we want to change it's output render     var isSeparatorFieldCtx = {}; ...