SiteManager

SiteManager is still available on SharePoint 2013.

_layouts/sitemanager.aspx

Validation on SharePoint forms

In some cases there is a business requirement where you need a mendatory column even if it isn’t as a mendatory column defined. Therefore you can use the standard .Net validation.

  • Open SharePoint Designer and create a new form.
  • Go to the place where you need an additional validation and disable the SharePoint control.
    Create a new .Net control by using asp:Textbox.
    Please keep in mind that your control should use the same ID. Use “__designer:bind” as well.
    For a better understanding what’s going on with the ddwrt:DataBind visit this site (http://www.bryancook.net/2009/09/understanding-sharepoints-ddwrtdatabind.html).
  • change the PropertyName and eventName from ‘Value’,’ValueChanged’ to ‘Text’,’TextChanged’
  • Add JavaScript Event

<!– New control –>
<span id=”suvNr”><asp:TextBox onkeydown=”return isNumberKey(event);”  runat=”server” id=”ff1{$Pos}” __designer:bind=”{ddwrt:DataBind(‘i’,concat(‘ff1’,$Pos),‘Text’,‘TextChanged’,’ID’,ddwrt:EscapeDelims(string(@ID)),’@Suppliernumber’)}” type=”number”/>
< /span><span id=”suvNrValidate”></span>

< !– Disable the SharePoint control: –>
<!–<SharePoint:FormField runat=”server” id=”ff1{$Pos}” ControlMode=”New” FieldName=”Suppliernumber” __designer:bind=”{ddwrt:DataBind(‘i’,concat(‘ff1′,$Pos),’Value’,’ValueChanged’,’ID’,ddwrt:EscapeDelims(string(@ID)),’@Suppliernumber’)}”/>
–>

  • disable the SharePoint Save Buttons and insert new one

<!– Original SharePoint Save Button must be disabled –>
<!– <SharePoint:SaveButton runat=”server” ControlMode=”New” id=”savebutton1″/>–>
<!– new Button Control –>
<input name=”Submit” type=”submit” value=”Submit” style=”font-size: 11px; width: 126px;” onclick=”javascript: if (!PreSaveAction()) return false; {ddwrt:GenFireServerEvent(‘__commit;__redirect={/sitedirectory/mm/SitePages/Home.aspx}’)}”/>

  • Add jQuery Script

<script type=”text/ecmascript” src=”http://code.jquery.com/jquery-1.11.1.js”></script>

  • Add Script

<script>
/* Disable the save control from the ribbon */
$( document ).ready(function() {
$( “a:contains(‘Save’)” ).css( “visibility”, “hidden” );
});

/* allows only characters*/
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode > 105 || charCode < 96))
{
alert(“Only characters are allowed!”);
return false;
}
return true;
}

/* Do actions before save form */
function PreSaveAction()
{
var valueSUV = $(“span#suvNr input”).val();
if(valueSUV.length > 0)
{
$( “span#suvNrValidate” ).text( “” );
return true;
}
$( “span#suvNrValidate” ).text( “You must specify a value for this required field.” );
$( “span#suvNrValidate” ).css({“color”:”red”,”padding-left”:”3px”});
}
</script>

DataViewWebpart in matrix display with XSLT modifications

Starting point:

  • SharePoint document library with documents
  • Documents use Category: Global, Regional and Local
  • Each document use a title. Needed for grouping.
  • Calculated-Column to generate a sorting order

Objective point:

  • Documents should be arrange in a matrix.
  • Header column displays the category
  • One document with the same title will and different categories should be display in one row.

Solution:

  • Using SharePoint Designer
  • Adding new DataView WebPart
  • Modify the XSLT

<xsl:template name=”dvt_1″>
<xsl:variable name=”dvt_StyleName”>2ColFrm</xsl:variable>
<xsl:variable name=”Rows” select=”/dsQueryResponse/Rows/Row” />

<xsl:variable name=”dvt_RowCount” select=”count($Rows)” />
<xsl:variable name=”dvt_IsEmpty” select=”$dvt_RowCount = 0″ />
<xsl:choose>
<xsl:when test=”$dvt_IsEmpty”>
<xsl:call-template name=”dvt_1.empty” />
</xsl:when>
<xsl:otherwise>
<table width=”100%” border=”1px” cellpadding=”0″ cellspacing=”0″>
<tr>
<th style=”padding: 4px;”>Product name</th>
<th style=”padding: 4px;”>Global</th>
<th style=”padding: 4px;”>Regional</th>
<th style=”padding: 4px;”>Local</th>
</tr>

<xsl:call-template name=”dvt_1.body”>
<xsl:with-param name=”Rows” select=”$Rows” />
</xsl:call-template>

</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name=”dvt_1.body”>
<xsl:param name=”Rows” />
<xsl:for-each select=”$Rows[@txtIWCOrder != ”]”>
<xsl:sort select=”@txtIWCOrder” />
<xsl:call-template name=”dvt_1.rowview” />
</xsl:for-each>

</xsl:template>

<xsl:template name=”dvt_1.rowview”>
<xsl:variable name=”pos” select=”position()”/>
<!–<xsl:variable name=”previewItemID”><xsl:value-of select=”substring-after(preceding-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>–>
<xsl:variable name=”previewItemName”><xsl:value-of select=”substring-before(preceding-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>
<xsl:variable name=”nextItemName”><xsl:value-of select=”substring-before(following-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>
<!–<xsl:variable name=”nextItemID”><xsl:value-of select=”substring-after(following-sibling::*[1]/@txtIWCOrder, ‘#’)”/></xsl:variable>–>
<xsl:variable name=”currentItemID”><xsl:value-of select=”substring-after(@txtIWCOrder,’#’)”/></xsl:variable>
<xsl:variable name=”currentItemName”><xsl:value-of select=”substring-before(@txtIWCOrder,’#’)”/></xsl:variable>

<xsl:choose>
<xsl:when test=”position()=1″>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Beginn”&gt;</xsl:text>
<td style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>

<xsl:choose>
<xsl:when test=”$currentItemID = 1″>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 2″>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 3″>
<td  align=”center”>-</td>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
</xsl:when>
</xsl:choose>

</xsl:when>
<xsl:when test=”$currentItemName = $nextItemName”>
<!– n-node –>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Equal”&gt;</xsl:text>
<td class=”Equal” style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>
<td class=”multiple-CurNext”  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>

</xsl:when>
<xsl:when test=”$currentItemName != $nextItemName”>
<xsl:if test=”$currentItemName != $previewItemName”>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Single”&gt;</xsl:text>
<td style=”padding:4px;”>
<xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>

<xsl:choose>
<xsl:when test=”$currentItemID = 1″>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 2″>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
<xsl:if test=”$nextItemName !=$currentItemName”><td  align=”center”>-</td></xsl:if>
</xsl:when>
<xsl:when test=”$currentItemID = 3″>
<td  align=”center”>-</td>
<td  align=”center”>-</td>
<td  align=”center”><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>
</xsl:when>
</xsl:choose>

<xsl:text disable-output-escaping=”yes”>&lt;/tr&gt;</xsl:text>
</xsl:if>

<xsl:if test=”$currentItemName = $previewItemName”>
<!– Only table section headline –>
<xsl:if test=”$currentItemName = $nextItemName”>
<xsl:text disable-output-escaping=”yes”>&lt;tr class=”Multiple”&gt;</xsl:text>
<td style=”padding:4px;”> <xsl:value-of select=”@Title” disable-output-escaping=”yes”/>
</td>
</xsl:if>
<td  class=”multiple” align=”center” ><a href=”{@FileDirRef}/{@FileLeafRef}” title=”{@Title} – {@Category}”>X</a></td>

<xsl:if test=”$currentItemName != $nextItemName”>
<td  class=”multiple-empty” align=”center”>-</td>
</xsl:if>
</xsl:if>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
<xsl:if test=”position() = last()”>
<xsl:text disable-output-escaping=”yes”>&lt;/tr&gt;</xsl:text>
</xsl:if>
</xsl:template>

Create SPGroups with PowerShell

You can create via PowerShell SharePoint Groups for a specific SiteCollection.

$siteURL = “http://intramania.com/sites/mysitecollection
$web = Get-SPWeb $siteURL
$groups = $web.SiteGroups
$groups.Add(“My-Group-Name-01”, $web.CurrentUser, $null, “SharePoint Group Name 01”)
$groups.Add(“My-Group-Name-02”, $web.CurrentUser, $null, “SharePoint Group Name 02”)
$groups.Add(“My-Group-Name-03”, $web.CurrentUser, $null, “SharePoint Group Name 03”)
$groups.Add(“My-Group-Name-04”, $web.CurrentUser, $null, “SharePoint Group Name 04”)
$groups.Add(“My-Group-Name-05”, $web.CurrentUser, $null, “SharePoint Group Name 05”)

PowerShell: Get creation date of all Site Collection in farm

Get creation date of all site collections in all Web-applications:

$Sites=@();
Get-SPSite -limit ALL|%{
$RootWeb = $_.RootWeb;
$Created = $RootWeb.Created;
$Sites += New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created=$Created}
write-host $Sites
$RootWeb.Dispose();
$_.Dispose();
}
$Sites|Export-CSV “C:\SiteCollectionCreated.csv” -NoTypeInformation;

Set Date with EventReceiver

properties.AfterProperties[“ApprovedTimeStamp”] = DateTime.Now.ToString(“yyyy-MM-ddTHH:mm:ssZ”); // Works Fine

properties.AfterProperties[“ApprovedTimeStamp”] = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now); // Works Fine