Total Pageviews

Showing posts with label SharePoint 2013. Show all posts
Showing posts with label SharePoint 2013. Show all posts

22 Jun 2018

Determine if SharePoint has enough memory allocated to the distributed cache service

After reading half a dozen articles explaining how to eyeball and calculate the distributed cache size I was wondering: Why no one suggests just to check the current consumption before changing anything? Here is a scary thought: What if we have a ton of memory and we don't need to add any more? I know, this sounds revolutionary.

This is a quick script that I've slapped together to show 1) maximum allocated memory for  the Distributed cache. 2) current usage for all AppFabric caches on the current server.

So, before bumping the Distributed cache, test the current consumption with the script below.


###### DETERMINE IF YOU HAVE ENOUGH MEMORY ALLOCATED TO DISTRIBUTED CACHE:
Add-PSSnapin Microsoft.SharePoint.Powershell
Use-CacheCluster
$hostname = hostname
$configuration = Get-AFCacheHostConfiguration -ComputerName $hostname -CachePort "22233"
Write-host Maximum Size: $($configuration.size)MB HostName: $($configuration.HostName) -ForegroundColor Blue
# Get-AFCache | % {Get-AFCacheConfiguration -CacheName $_.CacheName}
$caches = Get-AFCache | % {Get-AFCacheConfiguration -CacheName $_.CacheName}

 foreach($cache in $caches){
  $stats = Get-AFCacheStatistics $cache.CacheName
  Write-host $cache.CacheName -ForegroundColor Green Cache.
  Write-host Usage: $($stats.Size / 1MB) MB
  Write-host
 }

###### DETERMINE IF YOU HAVE ENOUGH MEMORY ALLOCATED TO DISTRIBUTED CACHE END

Here is the sample result:


22 Oct 2016

The Best Way to Develop SharePoint Client Side Applications

 

Please, read these articles by Andrew Koltyakov.

He explains in great detail how to properly develop client side solutions using tools like node, gulp, Visual Studio Code with SharePoint

11 Oct 2016

Stefan Goßner: PSCONFIGUI.EXE vs PSCONFIG.EXE

Nice article: Why I prefer PSCONFIGUI.EXE over PSCONFIG.EXE by Stefan Goßner

In case you need to use PSCONFIG.EXE to automate some tasks you should use the following command:

PSConfig.exe -cmd upgrade -inplace b2b -wait -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install

17 Mar 2015

Hide SharePoint 2013 Controls on Full Screen Mode

How do I hide or Show custom controls in full scree mode?




When you click on "full screen mode" button ms-fullscreenmode  class is added to the <Body> tag:



Solution:


A sample snippet of CSS that will hide your controls in full screen

/*hide controlID div only when full screen mode is enabled/
.ms-fullscreenmode #controlID {
 display:none;
}


#controlID - id of an HTML element that should be hidden when "full screen" is clicked

18 Jan 2014

Check if a Field was Changed Inside ItemUpdated Handler of a List EventReceiver

I think, I found the easiest way to check if a particular field was changed inside ItemUpdated handler. Here is what you should do:
  1. Add a new hidden field to the list.
  2. Register a new EventReceiver for ItemUpdating. It will save previous field values.
  3. In ItemUpdating save a field value from before properties of the field to afterProperties of the hidden field.
  4. In ItemUpdated compare afterProperties of the wanted field with the after properties of the hiddenField
2. Registering event receivers inside a feature receiver with the web scope:


 private static void AddEventReceivers(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb) properties.Feature.Parent;
            string assembly = Assembly.GetExecutingAssembly().FullName;

            web.AllowUnsafeUpdates = true;

            SPList list = GetTheListSomehow();
            SPEventReceiverDefinition ERDefinitionUpdated = list.EventReceivers.Add();
            ERDefinitionUpdated.Assembly = assembly;
            ERDefinitionUpdated.Class = typeof(Event_Receiver_Class).FullName;
            ERDefinitionUpdated.Type = SPEventReceiverType.ItemUpdated;
            ERDefinitionUpdated.Name = "ClipsEventReceiverItemUpdated";
            ERDefinitionUpdated.Update();

            SPEventReceiverDefinition ERDefinitionUpdating = list.EventReceivers.Add();
            ERDefinitionUpdating.Assembly = assembly;
            ERDefinitionUpdating.Class = typeof(Event_Receiver_Class).FullName;
            ERDefinitionUpdating.Type = SPEventReceiverType.ItemUpdating;
            ERDefinitionUpdating.Name = "ClipsEventReceiverItemUpdating";
            ERDefinitionUpdating.Update();
}


3. ItemUpdating EventReceiver:

public override void ItemUpdating(SPItemEventProperties properties)
{
    //warning: you should check if the field is not null
    properties.AfterProperties["hiddenFieldName"] = properties.ListItem["fieldName"];
}
warning: do not try to save values straight the hidden field. You should use afterProperties instead like is shown above.

4. ItemUpdated EventReceiver:

public override void ItemUpdated(SPItemEventProperties properties)
{
   string oldfieldValue = properties.ListItem["hiddenField"];

    //simplified example. you should check for nulls and maybe use a better way of comparing field values
   if (String.Equals(oldfieldValue, properties.AfterProperties["fieldName"]))
   {
       return;
   }
   //some code...
}



15 Jan 2014

Send Email with HTML Link to the Current User with SPUtility.SendEmail


Code:
        private void SendEmailWithReportLink(SPWeb web)
        {
            string bodyText = "To see the report <a href='" + "/_layouts/report.aspx" + "'>click here</a>. <br>";
            Boolean emailSent = true;
            SPSecurity.RunWithElevatedPrivileges(delegate() { 
                emailSent = SPUtility.SendEmail(web, true,false, SPContext.Current.Web.CurrentUser.Email,
                    "Report «Quality Control Summary» is ready", bodyText, true);
            
            });

            if (emailSent)
            {
               //TODO: log message
            }
            else
            {
                //TODO: log error
            }
        }

10 Jan 2014

SharePoint 2013 Feature Comparison All in One (credits to Peter Ekerot)

Here is a link to the Excel file with the comprehensive comparison across different versions of SharePoint 2013


Increase the Width of the Lookup Control

If you need to increase the width of the lookup field on the edit form - add this piece of CSS to your master page:


.ms-formtable table.ms-long {
    width:650px !important;
}

.ms-formtable table.ms-long .ms-input>select {
    width:300px !important;
}

The result should look like so:

4 Jan 2014

Using AppFabric Programmatically on SharePoint 2013 Farm

First of all, if you are going to use standard App Fabric cluster that goes with the prerequisites for SharePoint 2013 you'll end up being unsupported by Microsoft:

If you are using custom applications in SharePoint Server 2013 which use the AppFabric client APIs, or are creating custom caches, you should create a separate AppFabric cache cluster to support your custom applications. Do not use the AppFabric cache cluster supporting your SharePoint Server 2013 farm. Run your separate AppFabric cache cluster for your custom applications on separate servers from the servers dedicated to your SharePoint Server 2013 farm.

If you still want to use the OOB AF cluster, here is a sample code for it:

 static void Main(string[] args)
    {
        List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>();
        servers.Add(new DataCacheServerEndpoint("server.domain", 22233));
        DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
        configuration.ChannelOpenTimeout = TimeSpan.FromSeconds(120);
        configuration.IsCompressionEnabled = false;
        configuration.MaxConnectionsToServer = 10;
        configuration.RequestTimeout = TimeSpan.FromSeconds(120);
        configuration.Servers = servers;
        configuration.TransportProperties.MaxBufferSize = 1000000;
        DataCacheFactory dataCacheFactory = new DataCacheFactory(configuration);
        DataCache cache = dataCacheFactory.GetCache("DistributedDefaultCache_" + SPFarm.Local.Id);

        if (cache.Get("MyKEY") == null)
        {
            cache.Add("MyKEY", DateTime.Now);
        }
        DateTime dt = (DateTime)cache.Get("MyKEY");
        Console.WriteLine(dt);
    }

Note that you need to get the list of all servers in your cluster. In order to do it dynamically, you can use this piece of code:
string cacheClusterName = "SPDistributedCacheCluster_" + SPFarm.Local.Id;
var cacheClusterManager = SPDistributedCacheClusterInfoManager.Local;
var cacheClusterInfo =     cacheClusterManager.GetSPDistributedCacheClusterInfo(cacheClusterName);

foreach (var cacheHost in cacheClusterInfo.CacheHostsInfoCollection)
{
  servers.Add(new DataCacheServerEndpoint(cacheHost.HostName, cacheHost.CachePort));
}
I've also found a very decent helper class for working with OOB App Fabric cache (credits to Bernado Nguyen-Hoan).

2 Jan 2014

Generating Lots of List Items and Docuiments for Testing Purposes

I've uploaded a first version of List Manager for SharePoint utility on CodePlex.

It saves me a lot of time on generating list items for testing puroposes. It can also fill most of the field types including Multichoice, Lookups and Taxonomy metadata fields. It can generate text and word documents in case you need it.



This utility does not use bulk operations yet, so it might be a bit slow when generating thouthands of items, but it does its job in the end.

Here is a short demo:

SPRemoteAPIExplorer by Steve Curran MVP


A Visual Studio server explorer extension to provide the ability to explore and discover SharePoint 2013 remote API capabilities in REST and CSOM(Javascript, .Net and Silverlight). This extension is very useful when working with the SharePoint 2013 REST api. It lists all the types, methods, parameters and properties available to be called remotely. Metadata for types, methods and properties lists whether it can be used by CSOM, REST, JSOM and .Net remote api. Other information available in the property grid includes, OData type, whether to call the method using a querystring, path or body.  Requires Microsoft SharePoint 2013 installed locally and the Office Developer Tools for Visual Studio 2012.

13 Dec 2013

Change "SharePoint" in ms-core-brandingtext

In case you were wondering how to change "SharePoint" text in the top left corner:



In SharePoint Management PowerShell:

$app = get-spwebApplication "http://mysite"
$app.SuiteBarBrandingElementHtml = "<div class='ms-core-brandingText'>Custom Brand</div>"
$app.Update()

Done!




20 Nov 2013

Create Virtual Machine with Preinstalled SharePoint 2010/2013 Development Environment.

Here are the steps you should follow in order to create a preinstalled environment on a virtual machine:

  1. Install Windows Server 2008 R2/Windows Server 2012
  2. Install SharePoint 2013/2010 with all updates and do not run SharePoint Configuration Wizard
  3. You can install Visual Studio
  4. You can install Microsoft Office
  5. Do not install SQL Server because it can't be sysprepped.
  6. Do not enter any domains. Just because it's useless and I haven't checked whether it works or not.
  7. run C:\Windows\System32\Sysprep\Sysprep.exe
    1. Make sure you've checked "Generalize" option:
  8. Backup your virtual machine for later reuse
After you run your virtual environment you will need to:
  1. Install Domain controller role if it's a standalone Development environment.
  2. Join a domain (in case of SharePoint 2013) 
  3. Install SQL Server (optional)
  4. Run SharePoint Configuration Wizard
Conclusion:
There is only one mandatory step (Run SharePoint Configuration Wizard) you will need to do on your sysprepped virtual machine. Very convenient.

9 Nov 2013

ShowField="NameWithPicture attribute breaks field rendering in SharePoint 2013

I've noticed that  ShowField="NameWithPicture" attribute  in SharePoint 2013 does not render properly:



So, instead of NameWithPicture value
<Field Name="Employee" ID="{33c2ee31-2927-4de3-8e7d-cc1f2676378b}" DisplayName="Сотрудник" Type="User" Required="TRUE" UserSelectionMode="PeopleOnly" UserSelectionScope="0" ShowField="NameWithPicture" /

you can use NameWithPictureAndDetails:
<Field Name="Employee" ID="{33c2ee31-2927-4de3-8e7d-cc1f2676378b}" DisplayName="Сотрудник" Type="User" Required="TRUE" UserSelectionMode="PeopleOnly" UserSelectionScope="0" ShowField="NameWithPictureAndDetails" />

The result should look simillar to:


I've also noticed, that you can also change the way user field is displayed. There is a number of ways this field can be rendered. Honestly, I had no idea you could do that!

Update (Solution #2):
Looks like after updating Visual Studio Projects from SP2010 to SP 2013 you can include <JSLink>clienttemplates.js</JSLink> node into your View in schema.xml:


This will allow you to render User field with  ShowField="NameWithPicture" properly.


6 Aug 2013

Feature Stapling changes for MySites in SharePoint 2013

In case of My Sites, Elements.xml for the feature stapler you have to change TemplateName="SPSPERS#0"  to TemplateName="SPSPERS#2"

So, the resulting XML might look just like that:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <FeatureSiteTemplateAssociation Id="91a39059-e694-4c80-8341-e18db90c0c58"
           TemplateName="SPSPERS#2"/>
</Elements>

2 Aug 2013

Download and Install SharePoint 2013 Prerequisites on Windows Server 2012

These PowerShell scripts will automate downloading and installing the SharePoint 2013 Prerequisites on Windows Server 2012. The scripts will assist those who need to install SharePoint 2013 'offline' or wish to manually install its Prerequisites on Windows Server 2012.
Here is the link

Detect installed SharePoint 2010 or 2013 products using PowerShell

This PowerShell function returns a hash table to the pipeline containing SharePoint 2010 or 2013 products and the SharePoint Build Version installed on your server.
Here is the link.

26 Jul 2013

Allowing C# on Master Page and Layout Pages

1. Open web.config;
2. Find PageParserPaths node;
3. Add the following PageParserPath none so that it looks like so:
<PageParserPaths>
   <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="True" IncludeSubFolders="True" />
</PageParserPaths>