Monday 25 May 2015

Service error - "Memory gates checking failed because the free memory (xxxxx bytes) is less than 5% of total memory."

I was testing few service scripts when I encounter with this error -

"Memory gates checking failed because the free memory (xxxxxxxxx bytes) is less than 5% of total memory."

Resolution:

Adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element or your project config file.

The easiest way just add this into your web.config

<system.serviceModel>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />

</system.serviceModel>

Reference:
1) http://support.ge-ip.com/support/index?page=kbchannel&id=23301025e79bf210148caf0ad63007ec5
2) http://stevemannspath.blogspot.in/2012/07/sharepoint-2013-opening-memory-gates.html

Friday 22 May 2015

SharePoint 2010/2013: Updating Master Pages and Page layouts

Recently I have a task to replace masterpage manually(Programmatically). I tried to do it creating a module and putting masterpage inside it. But IgnoreIfAlreadyExists attribute within Module element can be tricky because sometimes it doesn’t work properly to update the MasterPages and PageLayouts.

Here is my solution for the update masterpage and Page layouts:

Feature Activation Code sample:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            if (properties != null)
            {
                using (SPSite currentSite = (SPSite)properties.Feature.Parent)
                {
                    using (var web = currentSite.OpenWeb())
                    {
                        var ElementDefinitions = properties.Definition.GetElementDefinitions(CultureInfo.CurrentCulture);

                        foreach (SPElementDefinition ElementDefinition in ElementDefinitions)
                        {
                            if (ElementDefinition.ElementType == "Module")
                            {
                                Helper.UpdateFilesInModule(ElementDefinition, web);

                            }
                        }
                    }
                }
            }

        }

You need to add a new class in your solution named "Helper" and add below code in it.

Namespaces:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.Xml.Linq;
using System.IO;
using Microsoft.SharePoint;
using System.Xml;

using System.Collections;

Class Code:

internal static class Helper
    {
        internal static void UpdateFilesInModule(SPElementDefinition elementDefinition, SPWeb web)
        {
            XElement xml = elementDefinition.XmlDefinition.ToXElement();
            XNamespace xmlns = "http://schemas.microsoft.com/sharepoint/";
            string featureDir = elementDefinition.FeatureDefinition.RootDirectory;
            Module module = (from m in xml.DescendantsAndSelf()
                             select new Module
                             {
                                 ProvisioningUrl = m.Attribute("Url").Value,
                                 //PhysicalPath = Path.Combine(featureDir, m.Attribute("Path").Value),
                                 Files = (from f in m.Elements(xmlns.GetName("File"))
                                          select new Module.File
                                          {
                                              Name = f.Attribute("Url").Value,
                                              PhysicalPath = Path.Combine(featureDir, f.Attribute("Path").Value),
                                              Properties = (from p in f.Elements(xmlns.GetName("Property"))
                                                            select p).ToDictionary(
                                                              n => n.Attribute("Name").Value,
                                                              v => v.Attribute("Value").Value)
                                          }).ToArray()
                             }).First();

            if (module == null)
            {
                return;
            }

            foreach (Module.File file in module.Files)
            {
                string physicalPath = file.PhysicalPath;
                string virtualPath = string.Concat(web.Url, "/", module.ProvisioningUrl, "/", file.Name);

                if (File.Exists(physicalPath))
                {
                    using (StreamReader sreader = new StreamReader(physicalPath))
                    {
                        if (!CheckOutStatus(web.GetFile(virtualPath)))
                        {
                            web.GetFile(virtualPath).CheckOut();
                        }
                        SPFile spFile = web.Files.Add(virtualPath, sreader.BaseStream, new Hashtable(file.Properties), true);
                        spFile.CheckIn("Updated", SPCheckinType.MajorCheckIn);
                        if (CheckContentApproval(spFile.Item))
                        {
                            spFile.Approve("Updated");
                        }

                        spFile.Update();
                    }
                }
            }

        }

        private static bool CheckOutStatus(SPFile file)
        {
            if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private static bool CheckContentApproval(SPListItem listitem)
        {
            bool isContentApprovalEnabled = listitem.ParentList.EnableModeration;

            return isContentApprovalEnabled;
        }

        public static XElement ToXElement(this XmlNode node)
        {
            XDocument xDoc = new XDocument();

            using (XmlWriter xmlWriter = xDoc.CreateWriter())

                node.WriteTo(xmlWriter);

            return xDoc.Root;

        }
    }

    public class Module
    {
        public string ProvisioningUrl { get; set; }
        //public string PhysicalPath { get; set; }
        public Module.File[] Files { get; set; }

        public class File
        {
            public string Name { get; set; }
            public string PhysicalPath { get; set; }
            public Dictionary<string, string> Properties { get; set; }
        }

    }

Reference: http://falakmahmood.blogspot.in/2011/09/sharepoint-2010-updating-masterpages.html

You can now check useful post links on "useful links" Right hand side top.



Wednesday 6 May 2015

How to find the Microsoft.SharePoint.Identitymodel.dll location in SharePoint-2013 development environment?

I was searching on "session timeout and setup sliding sessions on an FBA enabled site". Where i need to add a reference namespace "Microsoft.SharePoint.IdentityModel". I have spend lot of time searching it and trying to add it in solution.

Please follow below steps to get the dll.

1. Open the Windows Explorer

2. Navigate to C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ Microsoft.SharePoint.IdentityModel

3. And you can find the dll here C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ Microsoft.SharePoint.IdentityModel\v4.0_15.0.0.0__71e9bce111e9429c


But it's not so simple some time as GAC_MSIL folder is not visible (Missing) in the assembly folder.

Here are few ways you can get it :

A)

  1. start > run > cmd
  2. type : "cd\windows\assembly"
  3. type: "attrib -r -h -s desktop.ini"
  4. type: "ren desktop.ini desktop.bak"

now open the GAC folder normally in your explorer. 
B)
  1. Run regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll
  2. shfusion.dll is an explorer extension DLL that gives a distinct look to the GAC folder. Unregistering this file will remove the assembly cache viewer and the GAC folder will be then visible as any normal folder in explorer.
  3. Open “%windir%\assembly\GAC_MSIL”.
Hope it helps you too.

Dependency feature 'PPSSiteCollectionMaster' for feature 'PPSSiteMaster' is not activated at this scope.

I was trying to create a new sub site under my site collection while working with SharePoint 2010 and I got the below error message.

Dependency feature 'PPSSiteCollectionMaster' (id: a1cb5b7f-e5e9-421b-915f-bf519b0760ef) for feature 'PPSSiteMaster' (id:0b07a7f4-8bb8-4ec0-a31b-115732b9584d) is not activated at this scope.

Resolution:


1. Go Site Actions -> Site Settings ->Site Collection Administration ->Site collection features -> Performance Point Services Site Collection Features -> Activate

2. Go Site Actions -> Site Settings ->Site Actions ->Manage site features -> Performance Point Services Site Features -> Activate

SharePoint Idle timeout for windows user.

Recently i was working on sign out idle user after certain minutes. After so much tiresome tries i was able to generate a JavaScript that log out windows authenticated user in each browser.

Here is the code that you need to add in master page.

var IDLE_TIMEOUT = 30*60; //seconds - need to sign out if idle for 30 min.
        var _idleSecondsCounter = 0;
        document.onclick = function () {
            _idleSecondsCounter = 0;
        };
        document.onmousemove = function () {
            _idleSecondsCounter = 0;
        };
        document.onkeypress = function () {
            _idleSecondsCounter = 0;
        };
        window.setInterval(CheckIdleTime, 1000);//milliseconds (1 sec = 1000 millisecond) check every 1 second for idle timeout

        function CheckIdleTime() {
            _idleSecondsCounter++;
           
            if (_idleSecondsCounter >= IDLE_TIMEOUT) {
                document.location.href = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + "/_layouts/15/closeConnection.aspx?loginasanotheruser=true?Source=";
            }
        }