Archive for Uncategorized

SHAREPOINT 2013 vs 2016

FEATURES

SHAREPOINT
2013

SHAREPOINT
2016

New Features

Hover your mouse pointer on  to know more details of each feature

MinRoles
MinRole Farm Topology
Zero Downtime Patching
Integrated Project Server
Increased File Size for Uploads 2 GB 10 GB
File Name Support for Special Characters
Content Database Size 200 GB 1+ TB
Site Collections Per Content Database 5,000 100,000
Fast Site Collection/Site Creation
Override 5,000 View Threshold
App Launcher
SharePoint Search Service Application Indexing 100 million items Indexing 500 million items
ODF Support for Document Libraries
ReFS File System Support
Durable Links
Search for Sensitive Content
SMTP Connection Encryption
Sites Page Pinning
Deprecated Features
ForeFront Identity Manager Client (FIM)
Support for SQL Express
SharePoint Foundation
Standalone Install Mode
Excel Services in SharePoint

SharePoint: Create an administration page in SharePoint central administration

Custom administration pages can be used in Central Administration for a variety of purposes. One such scenario can be creating a page in CA for storing database connection string and using it in timer jobs. In this post we will create an administration page and use persisted objects to store data in SharePoint configuration database.

Create an empty SharePoint 2010 project with the following structure:

Copy this markup to the SampleCAAdminpage.aspx page.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages.Administration, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormSection" src="~/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" src="~/_controltemplates/ButtonSection.ascx" %>
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/_admin/admin.master" Inherits="SampleCAAdminPage.Pages.SampleCAAdminPage, SampleCAAdminPage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a6ed85d3cc39e3bd" %>

EncodeMethod='HtmlEncode' />

runat="server">
EncodeMethod='HtmlEncode' />


EncodeMethod='HtmlEncodeAllowSimpleTextFormatting' />



Title="Database Connectionstring"
Description="Identify the connection string used for accessing the the database." >







Title="SharePoint List"
Description="Identify the list for data import." >





















Change the public key token in Page directive line to your value.

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/_admin/admin.master" Inherits="SampleCAAdminPage.Pages.SampleCAAdminPage, SampleCAAdminPage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a6ed85d3cc39e3bd" %> 

Use the following code in connection.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace SampleCAAdminPage.Configuration
{
public class Connection : SPPersistedObject
{
private readonly static string NAME = typeof(Connection).FullName;

[Persisted]
private string mConnectionString;

[Persisted]
private string mListName;

///
/// Initializes a new instance of the class.
///

public Connection()
: base()
{
}

///
/// Initializes a new instance of the class.
///

/// The parent.
public Connection(SPPersistedObject parent)
: base(Connection.NAME, parent)
{
}

public string ListName
{
get
{
return this.mListName;
}
set
{
this.mListName = value;
}
}

public string ConnectionString
{
get
{
return this.mConnectionString;
}
set
{
this.mConnectionString = value;
}
}

///
/// Gets the ClaimsConnection details from local.
///

public static Connection Local
{
get
{
Connection result = SPFarm.Local.GetChild(Connection.NAME);
if (null == result)
{
try
{
result = new Connection(SPFarm.Local);
result.Update();
}
catch (Exception ex)
{
return null;
}
}

return result;

}
}
}
}

Use following code in SampleCAAdminPage.cs class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.ApplicationPages;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;
using SampleCAAdminPage.Configuration;
using Microsoft.SharePoint.Utilities;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;

namespace SampleCAAdminPage.Pages
{
public class SampleCAAdminPage : ApplicationsManagementPage
{
protected InputFormTextBox txtConnectionString;
protected InputFormTextBox txtListName;
protected Button btnConnectionTest;
protected Button btnSubmit;

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!this.IsPostBack)
{
Connection connection = Connection.Local;

this.txtConnectionString.Text = connection.ConnectionString;
this.txtListName.Text = connection.ListName;
}
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
Connection connection = Connection.Local;
if (null != connection)
{
connection.ConnectionString = this.txtConnectionString.Text.Trim();
connection.ListName = this.txtListName.Text.Trim();
connection.Update();
SPUtility.Redirect(PageToRedirectOnOK, SPRedirectFlags.Static, HttpContext.Current);
}
}

protected void btnConnectionTest_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(this.txtConnectionString.Text))
{
connection.Open();
connection.Close();
ShowMessage(this.Page, "Connection succeeded.");
}
}
catch (Exception ex)
{
ShowMessage(this.Page, ex.Message);
}

}

public override string PageToRedirectOnCancel
{
get
{
return "/applications.aspx";
}
}

public override string PageToRedirectOnOK
{
get
{
return "/applications.aspx";
}
}

public static void ShowMessage(Page page, string text)
{
// build up javascript to inject at the tail end of the page
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.AppendLine("");

// add to the page
page.Controls.Add(new LiteralControl(stringBuilder.ToString()));
}

}
}

Use follwoing xml in Elements file of CustomAction element:



Id="XYZConfiguration"
Location="Microsoft.SharePoint.Administration.Applications"
Title="XYZ Configuration"
Sequence="100"
ImageUrl="/_layouts/images/CentralAdmin_Security_GeneralSecurity_32x32.png"
/>
Id="XYZConfiguration.AdminPage"
GroupId="XYZConfiguration"
Location="Microsoft.SharePoint.Administration.Applications"
Sequence="6"
Title="Configure XYZ Project"
Description="Use this to configure XYZ Project connection options"
UIVersion="4">


Ensure that the feature has Farm level scope:

Finally deploy the solution and go to CA and click on Application management. Notice the section for configuring XYZ project.

Enter and save database connection string and list name in the page.

Inside the timer job or any SharePoint code the above saved values can be retrieved as follows:

Connection con = Connection.Local;

string connectionString = con.ConnectionString;
string listName = con.ListName;

Add an event receiver to a specific list programmatically

 

Creating an event receiver allows you to catch events for specific list types. Such as custom lists, document libraries, announcements, … When we want to catch an event for a specific list, the standard procedure for creating an event receiver changes a bit.

There’s an article on MSDN which describes a method by editing the elements.xml file of an event receiver project. However, the same result can be achieved with code.

Basically, an event receiver template will create a feature file which holds a reference to the elements.xml file from the event receiver project. Inside this elements.xml file, the properties of the event receiver are defined, such as the type of list it will be bound to. We want to bypass the elements.xml file and manually attach the event receiver to a specific list’s event receivers. The binding itself will be written in a feature event receiver.

Start out with creating a new SharePoint 2010 project and select the Event Receiver template. Fill in any desired properties and click on OK:

new event receiver project

Next, fill in the site where the list is at you want to attach the event receiver. Also choose “farm solution” as the desired trust level.

link farm solution

Click next, choose the event receiver settings. I’ve chosen for “List Item Events” where “An item was added” should be handled. The event source isn’t important, since we’ll override the binding:

event receiver settings

When finish is clicked, Visual Studio will create the files based on the template and the chosen settings. A feature will be created with a reference to the EventReceiver1 project. Inside this project an elements.xml file and a code file will be created. The elements.xml file holds the settings of the event receiver. The code file holds the code that will be executed:

event receiver solution explorer

Whenever you want to add more events that have to be captured, click on the EventReceiver1 project and look at the properties window. Here you can enable or disable events that have to be captured. Note that when you disable an already enabled event, the code inside the code file will not be removed. This is a safety built-in for when you accidentally disable an event:

event receiver properties

The next step is removing the connection between the feature and the event receiver project. By doing this we avoid that the elements.xml file is used to bind the event receiver. Double click on the feature file, select the EventReceiver1 project and click on the “<” arrow to remove the project from the feature:

remove event receiver from feature

Save the modification, and right-click the feature file to add a feature event receiver:

add event receiver

If it’s not already open, double-click the feature event receiver code file to open it up. Next, uncomment both FeatureActivated and FeatureDeactivating code blocks.

First, declare two constants in your feature class to keep constancy:

const string _listName = "test";
const SPEventReceiverType _eventType = SPEventReceiverType.ItemAdded;

Next, write the following code in the FeatureActivated block:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb oWeb = (SPWeb)properties.Feature.Parent;
oWeb.Lists[_listName].EventReceivers.Add(_eventType, Assembly.GetExecutingAssembly().FullName, "EventReceiverProject1.EventReceiver1.EventReceiver1");
}

You’ll notice that the Assembly namespace isn’t recognized so add the following line in your using statements:

using System.Reflection;

The last parameter of the Add() function can be found in the elements.xml file of the EventReceiver1 project. When you open this file you will see the 2 tags that are also referenced here in our code:

$SharePoint.Project.AssemblyFullName$
EventReceiverProject1.EventReceiver1.EventReceiver1

$SharePoint.Project.AssemblyFullName$ is replaced by Assembly.GetExecutingAssembly().FullName in the code.

The following code will remove the event receiver that was added:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb oWeb = (SPWeb)properties.Feature.Parent;

SPList oList = oWeb.Lists[_listName];
for (int i = oList.EventReceivers.Count - 1; i >=0 ; i--)
{
if (oList.EventReceivers[i].Type.Equals(_eventType))
{
try
{
oList.EventReceivers[i].Delete();
}
catch (Exception e)
{
// Write to logs
}
}
}
}

Retrieve value from SPFieldMultiLineText field in SharePoint

 

SPSite site = new SPSite("http://{yoursite}")) 
{
using (SPWeb web = site.OpenWeb())
{

SPList list = web.Lists["{YourList}"];
SPListItem result = list.GetItemById(1);
SPFieldMultiLineText commentsField = result.Fields.GetField("Comments") as SPFieldMultiLineText;

string comments = commentsField .GetFieldValueAsText(result["Comments"]);
string commentsAsHtml = commentsField .GetFieldValueAsHtml(result["Comments"]);
}
}

How to enable single sign-on to SharePoint?

Table of Contents

Introduction

Instructions

Introduction

You might have noticed that the UNC SharePoint Collaborative System frequently prompts you to login. It prompts you to login when you first open the site and prompts you to login again every time you open a Microsoft Office document. This can be a significant inconvenience, especially when using Shared Document libraries.

Fortunately, there is a solution that allows you to access SharePoint without ever having to login. This solution is referred to as single sign-on.

To use single sign-on, you must meet the following conditions:

1. Your computer must be a member of the AD.UNC.EDU or DEPTS.UNC.EDU domain. To determine your computer’s domain membership, seeWhat is my computer’s domain membership?

2. You must login to your computer using your domain account. You cannot login using a local account.

3. You must be granted permissions in SharePoint using the same account you use to login to your computer.

Instructions

The procedure to enable single sign-on to SharePoint depends on the browser you are using. Choose the instructions below that match your browser:

Microsoft Internet Explorer

To enable single sign-on in Internet Explorer, you must add the SharePoint site to your Intranet Sites. To do this:

1. Open Internet Explorer.

2. Click Tools > Internet Options

3. In the Security tab, select Local intranet and click the Sites button.

4. Click the Advanced button.

5. Enter the address https://share.unc.edu and click Add.

6. Click Close.

7. Click OK.

8. Click OK.

You should also verify that Integrated Windows Authentication is enabled.

1. Open Internet Explorer.

2. Click Tools > Internet Options

3. Click the Advanced tab.

4. In the Settings panel, scroll to the Security section. Ensure that Integrated Windows Authentication is enabled.

Mozilla Firefox

To enable single sign-on in Firefox, you must authorize the SharePoint site for automatic NTLM. To do this:

1. Open Firefox.

2. Enter about:config in the address bar of Firefox and press Enter.

3. In the Filter textbox, enter network.automatic-ntlm-auth.trusted-uris and press Enter.

4. Double click on network.automatic-ntlm-auth.trusted-uris to edit it.

5. Enter share.unc.edu and click OK.

How to hide the ribbon on dispalyform.aspx page of one of our lists?

 

Option I:

Using Cascading Stylesheet.

Edit the DispForm.aspx to that particular list in sharepoint designer and add the below style sheet code.

Option II:

using inline serverside code…

Edit the DispForm.aspx to that particular list in sharepoint designer and add the below style sheet code.

Modify web.config and add below tags.

Then you need to modify the application’s web.config in the virtual directory folder. Under the SafeMode node, add the following:

Note: change virtual path to your dispform.aspx.