Monday, February 23, 2015

Programatically increase security validation timeout for a web application in Sharepoint

Environment: SharePoint Server 2013

Requirement: Programatically increase security validation timeout for a web application in SharePoint

Solution: The following line of code will set the Web Page Security Validation expiry to 60 minutes

   SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://webappURL/"));

   //Use TimeSpan constructor to specify Days, hours, minutes, seconds
    webApp.FormDigestSettings.Timeout = new TimeSpan(1, 0, 0); 

  //Save the changes 

NoteYou'll get access denied error when the above code is executed within RWEP as it runs the code under the Application Pool account of the your web application. You need to run this code with farm account as the SPWebApplication is stored in config database. Use SPUserToken and farm account to run this code.

Wednesday, February 4, 2015

OpenSSL - No such file or directory

Scenario: Trying to convert csr certificate to crt using OpenSSL and getting following error
Command used: OpenSSL> x509 -req -in server.csr -signkey server.key -out server.crt

Loading 'screen' into random state - done
server.csr: No such file or directory
error in x509

Provide full path for both .csr and .key file to run this command successfully.

Sunday, January 4, 2015

Unable to add iframe in Content Editor WebPart SharePoint 2013 & IE 11

Using SharePoint 2013, IE 11

Issue: Cannot add iframe in Content Editor WebPart. Source page added in iframe is not getting displayed in IE 11. Works fine in Firefox and chrome browsers.

Script used: <iframe  id="iFrameBox" src=""></iframe>

Resolution: Add the script to load the source file on document ready function.

<script language="javascript" type="text/javascript">


<iframe  id="iFrameBox" src=""></iframe>

Tuesday, November 25, 2014

Too many characters in character literal

Issue: Getting "Too many characters in character literal" error when try to build a SharePoint project. Error in the following line of code in application page
Assembly Name="$SharePoint.Project.AssemblyFullName$"

Cause: Since the SharePoint project is a sandboxed solution, Sandboxed solutions do not support the application pages.

Resolution: Fixed it by changing the solution from Sandbox to farm.

Thursday, September 4, 2014

Remove duplicate Array from JArray

To remove duplicate array from JArray.

private static string RemoveDuplicateTasks(JArray strArray)

            JArray uniqueArray = new JArray();
            StringBuilder jsonResponse = new StringBuilder();

            //Loop through each array and find for array value with a specific column name. (ex: ID)
            foreach (JObject jObject in strArray)
                //Verify if the ID column value exist in the uniqueArray
                JObject rowObject = uniqueArray.Children<JObject>().FirstOrDefault(o => o["id"] != null && o["id"].ToString() == jObject.Property("id").Value.ToString());

                //rowObject will be null if these is no match for the value in ID column
                if (rowObject == null)

            //Remove the curly braces { }
            int strLength = uniqueArray.ToString().Length;
            string strValue = uniqueArray.ToString().Substring(1, (strLength - 2));
            jsonResponse.Append((jsonResponse.Length > 0 ? "," : "") + strValue);
            return "[" + jsonResponse.ToString() + "]";

Wednesday, July 9, 2014

Get SharePoint Groups added at Web level programmatically

To get SharePoint groups added to the specific web site/subsite level. Assumption is that the subsite is not inheriting permissions.

  private static List<string> GetAllWebGroups(string webUrl)
            List<string> lstGroups = new List<string>();

                    using (SPSite site = new SPSite(webUrl))
                        using (SPWeb spWeb = site.OpenWeb())
                            foreach (SPRoleAssignment roleAssignment in spWeb.RoleAssignments)
                                if (roleAssignment.Member is SPGroup)
                                    foreach (SPRoleDefinition roleDefinition in roleAssignment.RoleDefinitionBindings)
                                       // To get groups with specific role .
                                       //  SPRoleType.Editor does not work for SharePoint 2010
                                      /*The following condition will not return custom roles, remove this condition in case                                        you want to display all groups.*/
                                        if (roleDefinition.Type == SPRoleType.Reader ||
                                            roleDefinition.Type == SPRoleType.Contributor ||
                                            roleDefinition.Type == SPRoleType.WebDesigner ||
                                            roleDefinition.Type == SPRoleType.Administrator)
                                            if (!lstGroups.Exists(delegate(string sGroupName) { return sGroupName == roleAssignment.Member.Name; }))

Friday, May 16, 2014

Cannot complete this action as the Secure Store Shared Service is not responding. Please contact your administrator.

Using SharePoint 2013;

In IIS, change the secure store service Application pool identity to a dedicated user if it is pointed to Network service/Local Service.