Wednesday, 3 June 2015

Error - "Sorry, apps are turned off. If you know who runs the server, tell them to enable apps."

you will see this error when you try to add SharePoint Hosted app :

Sorry, apps are turned off. If you know who runs the server, tell them to enable apps.

Solution:

In order to install an App from the App Store you must setup an isolated App Domain, this is because Apps from the store deploy to their own app domain and run under a separate process from your SharePoint sites.

If your SharePoint site uses the DNS alias http://sharepoint.contoso.com you could have *.apps.contoso.com as your app domain.

http://www.sharepointalex.co.uk/index.php/2012/11/enabling-sharepoint-2013-apps/

How to: Set up an on-premises development environment for apps for SharePoint

http://msdn.microsoft.com/en-us/library/fp179923(v=office.15).aspx

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings.

I was working on hosted app when I encountered below error:

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings.


Solution:

Copy and paste below script in SharePoint Management Shell.

$acc = Get-SPManagedAccount <AccountName>
$appPool = New-SPServiceApplicationPool -Name "<Application pool name>" -Account $acc
$app = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPool –Name "Subscription Settings Service Application" –DatabaseName <Database name>
$proxy = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $app

Where
   Replace your <AccountName> with managed account
   Replace your <Application pool name> with Subscription Settings Service Apppool

   Replace your <Database name> with SPMT_Settings_Service_DB  

Reference:
https://technet.microsoft.com/en-us/library/fp161236(v=office.15).aspx

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=";
            }
        }

Thursday, 19 March 2015

How to develop SharePoint Library functionality Programatically? Part -1

Many times we need to provide some of the library functionality like check in, edit document, view document etc. programatically. Here are the sample code how you can implement in your code.

For Modal Popup please visit below link:
Sharepoint Modal Popup

 1) Check In : 

you need to call the function shown below to provide SharePoint check-in functionality for particular Item  programatically :

<li>
<a onclick="return OpenDocsDialog('web url/_layouts/15/checkin.aspx?List=ListGUID &FileName= fileurl&IsDlg=1');">
Check In
</a>.
</li>


2) Version History :
you need to call the function shown below to provide SharePoint Version History for particular Item  programatically :

<li>
<a onclick="return OpenDocsDialog('web url/_layouts/15/Versions.aspx?List=ListGUID &ID=CurrentItemID &IsDlg=1');">
Version History
</a>.
</li>

3) Workflow History:

you need to call the function shown below to provide SharePoint Workflow History for particular Item programatically :

<li>
<a onclick="return OpenDocsDialog('web url/_layouts/15/Workflow.aspx?ID=CurrentItemID &List= ListGUID &IsDlg=1');">
Workflow History
</a>.
</li>

4) View Property :
you need to call the function shown below to provide SharePoint view property of particular Item programatically :

<li>
<a href="#" onclick="return OpenDocsDialog( 'List URL/Forms/DispForm.aspx?ID=<%# Eval("ID") %>&IsDlg=1');">
View Property
</a>
</li>

5) Edit Property :
you need to call the function shown below to provide SharePoint Edit property of particular Item programatically :
<li>

<a href="#" onclick="return OpenDocsDialog('List URL/Forms/EditForm.aspx?ID=<%# Eval("ID") %>&IsDlg=1');">
Edit Property
</a>
</li>

Thursday, 26 February 2015

SharePoint Modal Pop Up.

If you like the popup SharePoint Uses and wants to implement such in your code here is the code sample that can meet your requirements.

function OpenDocsDialog(url1) {
        var options = {
            url: url1,
            dialogReturnValueCallback: myDialogCallback
        };
        SP.UI.ModalDialog.showModalDialog(options);      
    }

    function myDialogCallback(dialogResult, data) {
        SP.UI.ModalDialog.RefreshPage(dialogResult)
    }

Here is how you can call the function :

function OpenPopup1() {
        OpenDocsDialog("URL");
        return false;
    }


If you want to implement it directly here is the sample code:
SP.UI.ModalDialog.showModalDialog({
    url: dialogUrl,        
    allowMaximize: true,        
    showClose: true,        
    width: 400,        
    height: 200,        
    title: "Pop Up",        
    dialogReturnValueCallback: RefreshOnDialogClose
});

Monday, 16 February 2015

Filter Data Table in C#.

In general code data binding , most times we need to bind data through data table. In some case we might require to filter data. There are Three different ways you can filter data in data table.

  1. Using For loop. 
  2. Using Data view.
  3. Using Linq query.

Here we will see the demo for last two options.

A. Using data view.

Code Example:

DataTable  dt = GetDataTable(); //Get data in datatable
DataView dv = dt.DefaultView;
dv.RowFilter ="id=10"; // Filter column = filter value
dv.Sort =  "id"; //sort column (Desc for descending order)


repeater1.datasource = dv;
repeater1.databind();

The problem with data view is if the filter column does not match, it will return you the full table instead of null.

Helpful Blog :

B. Using Linq query

Code Example: 


DataTable dtdata = GetDataTable(); //Get data in datatable
                 
                        var data = (from dt in dtdata.AsEnumerable()
                                    where Convert.ToString(dt["id"]) == "10" 
                                    select dt
                                   ).ToList();
                        if (data.Count > 0)
                        {
                            DataTable dtlevel3 = new DataTable();
                            dtlevel3 = data.CopyToDataTable();
                            repeater1.datasource = dv;
                            repeater1.databind();
                        }

For c# code you will require to add namespace : using  System.Linq; 
For Sharepoint you need to add namespace : using Microsoft.SharePoint.Linq;

The "Mark as Decorative" Feature in SharePoint: A Small Toggle With a Big Accessibility Impact

If you've spent any time building pages in SharePoint Online, you've probably noticed a new checkbox tucked inside the Accessibility...