Tuesday, December 29, 2015

Create Site collection using power shell sharepoint 2013












Ex:1
New-SPSite -URL  "http://www.contoso.com/sites/eTeamSite"  -OwnerAlias "Contoso\Administrator" -Template "STS#0"


Ex:2

$template= Get-SPWebTemplate "STS#1"
New-SPSite  -URL "http://www.contoso.com/sites/Leere" -OwnerAlias "CONTOSO\GarethF" -Template $template


Saturday, March 28, 2015

SQL Blocking SQL Query

SELECT db.name DBName,
tl.request_session_id,
wt.blocking_session_id,
OBJECT_NAME(p.OBJECT_ID) BlockedObjectName,
tl.resource_type,
h1.TEXT AS RequestingText,
h2.TEXT AS BlockingTest,
tl.request_mode FROM sys.dm_tran_locks AS tl
INNER JOIN
sys.databases db ON db.database_id =tl.resource_database_id
INNER JOIN sys.dm_os_waiting_tasks AS wt
ON tl.lock_owner_address =wt.resource_address
INNER JOIN sys.partitions AS p ON
p.hobt_id =tl.resource_associated_entity_id
INNER JOIN sys.dm_exec_connections ec1 ON
 ec1.session_id =tl.request_session_id
INNER JOIN sys.dm_exec_connections ec2
ON
ec2.session_id =wt.blocking_session_id
CROSS APPLY  sys.dm_exec_sql_text(ec1.most_recent_sql_handle) AS  h1
CROSS APPLY  sys.dm_exec_sql_text(ec2.most_recent_sql_handle) AS  h2
GO



sp_who2

sp_who2  'spid'

kill  'spid'


Thursday, March 5, 2015

Information Rights Management :Protector could not be created as a generic COM object

Information Rights Management (IRM): Protector {78E40D5F-0C51-45B6-AC87-72119EC6669A} could not be created as a generic COM object (IUnknown). Protector: {78E40D5F-0C51-45B6-AC87-72119EC6669A} This indicates a major problem with the protector. Any COM object can be created as an IUnknown.

These errors are due to password protected filed being uploaded into SharePoint. Currently there is no action needed from an IT perspective.

Wednesday, March 4, 2015

List the available SharePoint site templates installed in your farm using Powershell

Get-SPWebTemplate | select ID, Name, Title | Sort-Object ID | Format-Table

Get-SPWebTemplate "STS#0"

List Active Databases used in sharepoint 2010 By Power Shell

Get List of All Databases
Goto SharePoint 2010 Management Shell

Get-SPDatabase | Sort-Objectdisksizerequired -desc | Format-Table Name

Get list of Content Databases

Get-SPContentDatabase | Sort-Object Name | Format-Table Name

Thursday, March 27, 2014

Event Receiver


SharePoint Item Event Receiver
public class EventReceiver1 : SPItemEventReceiver

    {
       /// <summary>
       /// An item is being added.
       /// </summary>
       public override void ItemAdding(SPItemEventProperties properties)
       {
           base.ItemAdding(properties);
           string workphone = properties.AfterProperties["WorkPhone"].ToString();
           string email = properties.AfterProperties["Email"].ToString();
           if (!string.IsNullOrEmpty(workphone))
           {
               if (!System.Text.RegularExpressions.Regex.IsMatch(workphone , @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$"))
               {
                   string sErrMsg = "Business Phone is not in correct format";
                   properties.ErrorMessage = sErrMsg;
                   //properties.Status = SPEventReceiverStatus.CancelWithError;
                   properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                   properties.RedirectUrl = string.Format("/_layouts/ListItemEventReceive/EventReceiverErrorPage.aspx?ErrMsg={0}",sErrMsg);
               }              
           }
           if (!string.IsNullOrEmpty(email))
           {
               if (!System.Text.RegularExpressions.Regex.IsMatch(email, @"^(?("")("".+?""@)|(([0-9a-zAZ]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zAZ]{2,6}))$"))
               {
                   string sErrMsg = "Email is not in correct format";
                   properties.ErrorMessage = sErrMsg;
                   //properties.Status = SPEventReceiverStatus.CancelWithError;
                   properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                   properties.RedirectUrl = string.Format("/_layouts/ListItemEventReceive/EventReceiverErrorPage.aspx?ErrMsg={0}", sErrMsg);
               }
           }
       }
    }

Application Page:

EventReceiverErrorPage.aspx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ 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" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EventReceiverErrorPage.aspx.cs" Inherits="ListItemEventReceive.Layouts.ListItemEventReceive.EventReceiverErrorPage" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:Label ID="lblErrMsg" runat="server" Text=""></asp:Label>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Event Receiver Error
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Event Receiver Error
</asp:Content>


EventReceiverErrorPage.aspx.cs

    public partial class EventReceiverErrorPage : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sErrMsg = Request.Params["ErrMsg"];
            lblErrMsg.Text = sErrMsg;
        }
    }



Friday, January 11, 2013

Visual Webpart "Hello" User / Hello World

Drag and Drop a Lable in Design

Code:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint; 

namespace VisualWebPartProject2.VisualWebPart1

{

    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = "<font color = blue'><marquee> Hello  "+ SPContext.Current.Web.CurrentUser.Name +"</marquee></font>";
        }
    }
}