Get Secure String Pass CSOM

Posted on Updated on

private static SecureString GetPass(string pass)
    // Instantiate the secure string.        
    var secureStr = new SecureString();
    if (pass.Length <= 0) return secureStr;
    foreach (var c in pass.ToCharArray()) secureStr.AppendChar(c);
    return secureStr;

Debugging Tool Apply to SharePoint

Posted on

The Debug Diagnostic Tool (DebugDiag 2.0) is designed to assist in troubleshooting issues such as hangs, slow performance, memory leaks or memory fragmentation, and crashes in any user-mode process.


You can download here

For support, news and feedback read Microsoft blog

Sample Training for SharePoint 2013

Posted on

Application - Chart

If you want to start a training plan, bellow are some guidelines that can be follow. Brainstorming in comments are welcome

This is only a sample if you want to create a plan from scratch

Module 1: Introducing SharePoint Server 2013

  • Key Components of a SharePoint Deployment
  • New Features in SharePoint 2013
  • SharePoint 2013 Deployment Options

After completing this module, you will be able to:

  • Identify the capabilities and architecture of SharePoint 2013.
  • Identify new and deprecated features in SharePoint 2013.
  • Identify deployment options for SharePoint 2013.

Module 2: Designing an Information Architecture

  • Identifying Business Requirements
  • Understanding Business Requirements
  • Organizing Information in SharePoint 2013
  • Planning for Discoverability

Lab : Creating an Information Architecture – Part One

  • Identifying Site Columns and Content Types

Lab : Creating an Information Architecture – Part Two

Designing a Business Taxonomy

  • After completing this module, you will be able to:
  • Explain how understanding business requirements drives the design of an organizational IA.
  • Describe the key components available in SharePoint 2013 to deploy an IA.
  • Plan for discoverability as part of an IA deployment.

Module 3: Designing a Logical Architecture


Overview of SharePoint 2013 Logical Architecture

Documenting Your Logical Architecture

Lab : Designing a Logical Architecture

Plan a Logical Architecture

  • Produce a Logical Architecture Diagram

After completing this module, you will be able to:

  • Map business requirements to SharePoint 2013 architecture components.
  • Explain the importance of documentation and describe the options for documenting logical architecture.

Module 4: Designing a Physical Architecture


  • Designing Physical Components for SharePoint Deployments
  • Designing Supporting Components for SharePoint Deployments
  • SharePoint Farm Topologies
  • Mapping a Logical Architecture Design to a Physical Architecture Design

Lab : Designing a Physical Architecture

  • Designing a Physical Architecture
  • Develop a Physical Architecture Design Diagram
  • After completing this module, you will be able to:
  • Describe the physical design requirements for SharePoint 2013.
  • Describe the supporting requirements for a successful SharePoint 2013 physical design.
  • Identify SharePoint farm topologies.
  • Map a logical architecture design to a physical architecture design.

Module 5: Installing and Configuring SharePoint Server 2013


  • Installing SharePoint Server 2013
  • Scripting Installation and Configuration
  • Configuring SharePoint Server 2013 Farm Settings

Lab : Deploying and Configuring SharePoint Server 2013 – Part One

  • Provisioning a SharePoint 2013 Server Farm

Lab : Configuring SharePoint Server 2013 Farm Settings

  • Configuring SharePoint Server 2013 Farm Settings
  • Configuring Outgoing Email
  • Configuring Integration with Office Web Apps Server 2013
  • After completing this module, you will be able to:
  • Install SharePoint 2013.
  • Configure SharePoint 2013 farm settings.
  • Script the installation and configuration of SharePoint 2013.

Module 6: Creating Web Applications and Site Collections


  • Creating Web Applications
  • Configuring Web Applications
  • Creating and Configuring Site Collections
  • Lab : Creating and Configuring Web Applications
  • Creating a Web Application
  • Configuring a Web Application

Lab : Creating and Configuring Site Collections

  • Creating Site Collections
  • Creating Site Collections in New Content Databases
  • Creating a Warm-up Script

After completing this module you will be able to perform the following tasks in SharePoint 2013:

  • Create web applications.
  • Configure web applications.
  • Create site collections.
  • Configure site collections.

Module 7: Planning and Configuring Service Applications


Introduction to Service Application Architecture

Creating and Configuring Service Applications

Lab : Planning and Configuring Service Applications

  • Provisioning a Managed Metadata Service Application with Central Administration
  • Provisioning a Managed Metadata Service Application with Windows PowerShell
  • Configuring Service Applications for Document Conversions
  • Configuring Service Application Proxy Groups
  • After completing this module, you will be able to:
  • Explain the key components and topologies for SharePoint Server 2013 service application architecture.
  • Describe how to provision and manage SharePoint 2013 service applications.

Module 8: Managing Users and Permissions


  • Authorization in SharePoint 2013
  • Managing Access to Content

Lab : Managing Users and Groups

Creating a Web Application Policy

Creating and Managing SharePoint Groups

Lab : Securing Content in SharePoint Sites

  • Managing Permissions and Inheritance
  • Managing Site Collection Security
  • Enable anonymous access to a site
  • After completing this module, you will be able to:
  • Understand and manage authorization and permissions in SharePoint 2013.
  • Manage access to content in SharePoint 2013.

Module 8:Creating Custom Permission Levels

Lab : Securing Content in SharePoint Sites

  • Managing Permissions and Inheritance
  • Managing Site Collection Security
  • Enable anonymous access to a site
  • After completing this module, you will be able to:
  • Understand and manage authorization and permissions in SharePoint 2013.
  • Manage access to content in SharePoint 2013.


Overview of Authentication

Configuring Federated Authentication

Configuring Server-to-Server Authentication

Lab : Configuring SharePoint 2013 to Use Federated Identities

  • Configuring AD FS to Make the Web Application a Relying Party
  • Configuring SharePoint to Trust AD FS as an Identity Provider
  • Configuring the Web Application to Use the AD FS Identity Provider
  • After completing this module, you will be able to:
  • Explain the authentication infrastructure of SharePoint 2013.
  • Configure claims providers and identity federation for SharePoint 2013.
  • Configure server-to-server authentication for SharePoint 2013.

Module 09: Managing Taxonomy


  • Managing Content Types
  • Understanding Term Stores and Term Sets
  • Managing Term Stores and Term Sets

Lab : Configuring Content Type Propagation

  • Creating Content Types for Propagation
  • Publishing Content Types Across Site Collections

Lab : Configuring and Using Managed Metadata Term Sets

  • Configuring the Managed Metadata Service
  • Creating Term Sets and Terms
  • Consuming Term Sets

After completing this module, you will be able to:

  • Describe the function of content types and explain how to apply them to business requirements.
  • Describe the function of managed metadata in SharePoint 2013.
  • Configure the Managed Metadata Service and supporting components.

Module 10: Configuring Enterprise Search


  • Monitoring a SharePoint 2013 Environment
  • Tuning and Optimizing a SharePoint Environment
  • Planning and Configuring Caching
  • Troubleshooting a SharePoint 2013 Environment

Lab : Monitoring a SharePoint 2013 Deployment

  • Configuring Usage and Health Data Collection
  • Configuring SharePoint Diagnostic Logging
  • Configuring Health Analyzer Rules
  • Reviewing Usage and Health Data

Lab : Investigating Page Load Times

  • Investigating Page Load Times
  • Analyzing SharePoint Page Performance

After completing this module, you will be able to:

  • Develop and implement a monitoring plan for a SharePoint 2013 environment.
  • Tune and optimize a SharePoint 2013 server farm on an ongoing basis.
  • Plan and configure caching to improve the performance of a SharePoint 2013 deployment.
  • Troubleshoot errors and other issues in a SharePoint 2013 deployment.

Remove Windows.old After Upgrade

Posted on Updated on

There are several ways to remove the Windows.old file after upgrade. In a Server scenario, you don’t want to add the feature for “Desktop Experience” that will consume memory.

As a Workaround for this, you can use Windows Console as Administrator


Now run the the bellow commands:

Step 1

This step is a long run operation, so you will have to wait until all files and folders take ownership for Administrator

takeown /F c:\Windows.old\* /R /A /D Y

Step 2

This step will grant all permissions to Administrator

cacls c:\Windows.old\*.* /T /grant administrators:F

Step 3

This step will remove finally the Windows.old directory

rmdir /S /Q c:\Windows.old

Good Luck

Custom Web Services SharePoint Part I – (LOB)

Posted on Updated on

  2. Writing….

Write custom WCF REST Web Services in SharePoint why?

  1. You have your data outside SharePoint
  2. You don’t want or can’t override  the default throttling limit
  3. You want to build a BCS Model for Search inside SharePoint
  4. You want to integrate a REST System independent of the Technology


Every system uses resources. These resources can be pictures, video files, Web pages, business information, or anything that can be represented in a computer-based system. The purpose of a service is to provide a window to its clients so that they can access these resources. Service architects and developers want this service to be easy to implement, maintainable, extensible, and scalable. A Restful design promises that and more. In general, Restful services should have following properties and features.

REST’s client–server separation of concerns simplifies component implementation, reduces the complexity of connector semantics, improves the effectiveness of performance tuning, and increases the scalability of pure server components. Layered system constraints allow intermediaries—proxies, gateways, and firewalls—to be introduced at various points in the communication without changing the interfaces between components, thus allowing them to assist in communication translation or improve performance via large-scale, shared caching. REST enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to indicate semantics and exchange information, and responses explicitly indicate cacheability.

I Prefer to use Linq 2 SQL in order to provide my Models, it’s faster than Entity Framework.


Microsoft: LINQ to SQL [LINQ to SQL]


public class RetServices
    public double? ServiceId { get; set; }
    public double? ServiceParentId { get; set; } 
    public string ServiceTitle { get; set; }

    public string ServiceRelated { get; set; }
[WebGet(UriTemplate = "GetServicesTree", BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
List<RetServices> GetSevicesTree();
public List<RetServices> GetServicesTree()
    var db = new YourContext(Cs);
    var ret = from s in db.YourTable
              select new RetServices
                  ServiceId = s.SER_ID,
                  ServiceParentId = s.SER_PARENT_ID,
                  ServiceTitle = s.NOME_SHORT,
                  ServiceRelated = s.SER_DIRECTOR.ToString()
    return ret.ToList();

You can put you SVC file wherever you want, since the DLL for the project with the DATA, INTERFACES and IMPLEMENTATIONS reside in the GAC or the Web Application BIN Folder

<@ ServiceHost Language="C#" Debug="true" Service="YourDLL.YourNamespace.YourClass" %>
I prefer to create a Mapped Folder and put it in the ISAPI (On Premises Only), but you can put it whatever, since you secure it
Point from Client Side:
function get_ServicesTree()
    cache: false,
type: "GET",
url: "/_vti_bin/YourFolder/YourService.svc/GetServicesTree",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$.each(data, function(key, value) {
error: function(jqXhr, status) { 
  <add name="LobConnectionString" connectionString="Data Source=SERVER;Initial Catalog=DATABASE;user=sa; pwd=xxxxx" />
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <service name="YOURDLL.YOURNAMESPACE.YOURCLASS" behaviorConfiguration="">
      <endpoint address="" binding="webHttpBinding" behaviorConfiguration="restfulBehavior" contract="YOURDLL.YOURNAMESPACE.IYourInterface">
          <dns value="localhost" />
          <add baseAddress="http://localhost/" />
      <behavior name="restfulBehavior">
        <webHttp helpEnabled="true" automaticFormatSelectionEnabled="true" />

Linq to SharePoint Date Difference in days

Posted on Updated on

When using Linq to SharePoint in a WCF REST Service, or other cases a good option is:

public string MyDays { get; set; } 
MyDays =  DateTime.Now.Subtract(p.EntityAsYOURDate.GetValueOrDefault()).Days + " days" 


Provisionate MasterPage and CSS with Feature

Posted on Updated on

Sometimes, when you don’t want to use Powershell, you can set your branding from a Feature, it’s the old procedure but very “elastic”.

In the bellow sample, I’ll give you the option to change you master page to Front Office and Back Office, you can also define your CSS File.

I’m processing all Sub Webs also, just change what you want. This is a Feature SCOPE Site

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    using (var site = properties.Feature.Parent as SPSite)
        if (site == null) return;
        using (var web = site.OpenWeb())
            var masterUrl = web.Site.ServerRelativeUrl == "/" ? 
                "/_catalogs/masterpage/YOURCustomFO.master" : web.Site.ServerRelativeUrl + 
            var customMasterUrl = web.Site.ServerRelativeUrl == "/" ? 
                "/_catalogs/masterpage/seattle.master" : web.Site.ServerRelativeUrl + 
            //string cssUrl = web.Site.ServerRelativeUrl == "/" ? "/Style Library/xx.css" : web.Site.ServerRelativeUrl + "/Style Library/xx.css";

            #region MasterPage e CSS

            // Define Master page for FO and BO
            web.CustomMasterUrl = masterUrl;
            web.MasterUrl = customMasterUrl;

            //Alternate CSS URL 
            //web.AlternateCssUrl = cssUrl;

            // inheritance settings
            web.AllProperties["__InheritsMasterUrl"] = "True";
            web.AllProperties["__InheritsCustomMasterUrl"] = "True";
            //web.AllProperties["__InheritsAlternateCssUrl"] = "True";


            foreach (SPWeb subWeb in web.Webs)
                    if (subWeb != null)

Some things you want to hide in your Master Page

Posted on Updated on

	/* Turns off the border on the bottom of the tabs */
	.ms-cui-ribbonTopBars > div {
		border-bottom: 1px solid transparent !important;
	/* Hide Ribbon */
	#s4-ribbonrow {
		display: none;

	/* Hide Suite Bar */
	#suiteBar {
		display: none;

	/* Remove Left Navigation Bar */
	#sideNavBox {
		DISPLAY: none;

	/* Remove Logo */
	#s4-titlerow {
		display: none !important;

ECMA Script SP.ClientContext to Json

Posted on Updated on

Want to convert to Json a list.getItems collection? this is the way using ECMA Javascript

Declare SP.js

<SharePoint:ScriptLink runat="server" Name="SP.js" Localizable="false" OnDemand="False" LoadAfterUI="True"></SharePoint:ScriptLink> 


JavaScript Function

function getJson() {
    var context = new SP.ClientContext("/");
    var list = context.get_web().get_lists().getByTitle("YourList"); 
    var viewXml = "<View><RowLimit>1000</RowLimit></View>";
    var query = new SP.CamlQuery();
    var items = list.getItems(query);
    context.load(items, "Include(Column1,Column2,Column3)");

    function onLoaded() {
        var myItems = [];
        var itemsCount = items.get_count();
        for (var i = 0; i < itemsCount; i++) {
            var item = items.itemAt(i);
            var myItem = JSON.stringify(item.get_fieldValues());


    function onFailure() {


In order to use JSON.parse() you must change the [Object<Array>] like this
var dt = "[" + MyItems + "]";
var ret = JSON.parse(MyItems); 

It will give you a [Object],[Object],[Object]

Enterprise Keywords TaxKeyword Tag Cloud

Posted on Updated on

In this post, i will help you to generate a Tag Cloud based on the TaxKeyword, the default enterprise TAG for SharePoint. This sample is for OOTB or not. I’m using SharePoint Search.

Let’s roll to the search method:

Now that we have the DataTable let´s get the Tags from the TAGS Field

/// <summary>
/// Executes the key word search.
/// </summary>
/// <param name="queryText">The query text.</param>
/// <param name="siteUrl"></param>
/// <param name="queryLimit"></param>
/// <returns></returns>
public DataTable ExecuteKeyWordSearch(string queryText, string siteUrl, int queryLimit)
    var retResults = new DataTable(); 
    using (var site = new SPSite(siteUrl))
        using (var query = new KeywordQuery(site))
            query.QueryText = queryText;
            query.KeywordInclusion = KeywordInclusion.AllKeywords;
            query.RowLimit = queryLimit;


            var se = new SearchExecutor();
            var rtc = se.ExecuteQuery(query);
            if (rtc.Count <= 0) return null;
            var results = rtc.Filter("TableType", KnownTableTypes.RelevantResults);
            var resultTables = results as IList<ResultTable> ?? results.ToList();
            if (results != null && resultTables.Count() == 1)
                retResults.Load(resultTables.First(), LoadOption.OverwriteChanges);
            return retResults;

Let’s replace all “L0|#” and remove all Guid’s

public List<string> GetSafeTagName(string tag)
    tag = tag
        .Replace("L0|#", "");
    tag = Regex.Replace(tag, @"([a-z0-9]{8}[-][a-z0-9]{4}[-][a-z0-9]{4}[-][a-z0-9]{4}[-][a-z0-9]{12})", ""); 
    char[] delimiter = { ';' };
    var parts = tag.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
    return parts.ToList();

var list = new List<string>(); 
foreach (var refiners in from dr in _dt.AsEnumerable()
                         where dr["Tags"].ToString() != string.Empty
                         select GetSafeTagName(dr["Tags"].ToString()))

After having our tags, let’s take a count for each TAG, I’m taking 11 for my render

var q = (from x in list
 group x by x
     into g
     let count = g.Count()
     orderby count descending
     select new { Value = g.Key, Count = count }).Take(11); 

So? Let´s render. I’m having a bug :), but let´s remove the first 2 characters

foreach (var x in q)


This is an example, but you can refine it. I’m taking the total, that is 11, and passing the xCount

private static string TagLogic(double xCount, double xTotal)
        string ret;
        var count = xCount;
        var percent = (count / xTotal) * 100; 
        if (percent < 20)
            ret = "10";
        else if (percent < 50)
            ret = "20";
        else if (percent < 70)
            ret = "50";

            ret = "70";
        return ret;