SharePoint 2010 provides a new set of technologies known as Business Connectivity Services for retrieving, editing, updating, and deleting data from external systems(for e.g. data from ERP or CRM database). BCS enhances the SharePoint platform’s capabilities with out-of-box features, services and tools that streamline development of solutions with deep integration of external data and services.
Monday, December 05, 2011
Getting Current Page Url using xslt.
<%@ Page language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" masterpagefile="~masterurl/default.master" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain">
<script language="javascript" type="text/javascript">
function getLinkDynamic()
{
var strUrl="/{@FileRef}/DispForm.aspx?ID={@ID}&Source=window.location.href";
return strUrl
}
</script>
<WebPartPages:SPProxyWebPartManager runat="server" id="ProxyWebPartManager">
</WebPartPages:SPProxyWebPartManager>
<table style="width: 100%">
<tr>
<td>
<WebPartPages:WebPartZone id="g_946A9FBBB7644CEFB36BBE70340D9A15" runat="server" title="Zone 1"><ZoneTemplate>
<WebPartPages:DataFormWebPart runat="server" SuppressWebPartChrome="False" Description="" PartImageSmall="" DataSourceID="" MissingAssembly="Cannot import this Web Part." ListName="{53175A92-E6CC-4464-8E5C-9C23436D0577}" FrameType="None" ConnectionID="00000000-0000-0000-0000-000000000000" DetailLink="" ExportControlledProperties="True" IsVisible="True" AllowRemove="False" AllowEdit="False" ID="g_6b7417ff_0b73_40ae_84bc_152313e9a2cd" Dir="Default" FrameState="Normal" DisplayName="Test" ViewContentTypeId="" AllowClose="False" AllowConnect="False" PageSize="-1" Default="FALSE" AllowMinimize="False" IsIncludedFilter="" ShowWithSampleData="False" ChromeType="None" HelpMode="Modeless" ExportMode="All" ViewFlag="0" Title="Test" HelpLink="" AllowHide="False" AllowZoneChange="False" PartOrder="1" UseSQLDataSourcePaging="True" PartImageLarge="" IsIncluded="True" NoDefaultStyle="TRUE" __MarkupType="vsattributemarkup" __WebPartId="{F3F8B212-E809-47FE-952C-E01E98F22F81}" __AllowXSLTEditing="true" WebPart="true" Height="" Width=""><DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="<View></View>" UseInternalName="True" ID="Test1"><SelectParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</SelectParameters><UpdateParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</UpdateParameters><InsertParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</InsertParameters><DeleteParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</DeleteParameters>
</SharePoint:SPDataSource>
</DataSources>
<ParameterBindings>
<ParameterBinding Name="ListID" Location="None" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}"/>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
<ParameterBinding Name="url_PATH_INFO" Location="ServerVariable(PATH_INFO)" DefaultValue=""/>
<ParameterBinding Name="url_HTTP_HOST" Location="ServerVariable(HTTP_HOST)" DefaultValue=""/>
</ParameterBindings>
<DataFields>@Title,Title;@Description,Description;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</DataFields>
<Xsl>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain">
<script language="javascript" type="text/javascript">
function getLinkDynamic()
{
var strUrl="/{@FileRef}/DispForm.aspx?ID={@ID}&Source=window.location.href";
return strUrl
}
</script>
<WebPartPages:SPProxyWebPartManager runat="server" id="ProxyWebPartManager">
</WebPartPages:SPProxyWebPartManager>
<table style="width: 100%">
<tr>
<td>
<WebPartPages:WebPartZone id="g_946A9FBBB7644CEFB36BBE70340D9A15" runat="server" title="Zone 1"><ZoneTemplate>
<WebPartPages:DataFormWebPart runat="server" SuppressWebPartChrome="False" Description="" PartImageSmall="" DataSourceID="" MissingAssembly="Cannot import this Web Part." ListName="{53175A92-E6CC-4464-8E5C-9C23436D0577}" FrameType="None" ConnectionID="00000000-0000-0000-0000-000000000000" DetailLink="" ExportControlledProperties="True" IsVisible="True" AllowRemove="False" AllowEdit="False" ID="g_6b7417ff_0b73_40ae_84bc_152313e9a2cd" Dir="Default" FrameState="Normal" DisplayName="Test" ViewContentTypeId="" AllowClose="False" AllowConnect="False" PageSize="-1" Default="FALSE" AllowMinimize="False" IsIncludedFilter="" ShowWithSampleData="False" ChromeType="None" HelpMode="Modeless" ExportMode="All" ViewFlag="0" Title="Test" HelpLink="" AllowHide="False" AllowZoneChange="False" PartOrder="1" UseSQLDataSourcePaging="True" PartImageLarge="" IsIncluded="True" NoDefaultStyle="TRUE" __MarkupType="vsattributemarkup" __WebPartId="{F3F8B212-E809-47FE-952C-E01E98F22F81}" __AllowXSLTEditing="true" WebPart="true" Height="" Width=""><DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="<View></View>" UseInternalName="True" ID="Test1"><SelectParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</SelectParameters><UpdateParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</UpdateParameters><InsertParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</InsertParameters><DeleteParameters><WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}" Name="ListID"></WebPartPages:DataFormParameter>
</DeleteParameters>
</SharePoint:SPDataSource>
</DataSources>
<ParameterBindings>
<ParameterBinding Name="ListID" Location="None" DefaultValue="{53175A92-E6CC-4464-8E5C-9C23436D0577}"/>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
<ParameterBinding Name="url_PATH_INFO" Location="ServerVariable(PATH_INFO)" DefaultValue=""/>
<ParameterBinding Name="url_HTTP_HOST" Location="ServerVariable(HTTP_HOST)" DefaultValue=""/>
</ParameterBindings>
<DataFields>@Title,Title;@Description,Description;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</DataFields>
<Xsl>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:param name="url_PATH_INFO" />
<xsl:param name="url_HTTP_HOST" />
<xsl:variable name="CurrentPageUrl" select="concat('http://',$url_HTTP_HOST,$url_PATH_INFO)" />
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="nowrap">Title</th>
<th class="ms-vh" nowrap="nowrap">Description</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<a href="/{@FileDirRef}/DispForm.aspx?ID={@ID}&Source={$CurrentPageUrl}" target="_blank"><xsl:value-of select="@Title" /></a></td>
<td class="ms-vb">
<xsl:value-of select="@Description"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet> </Xsl>
</WebPartPages:DataFormWebPart>
<xsl:param name="url_PATH_INFO" />
<xsl:param name="url_HTTP_HOST" />
<xsl:variable name="CurrentPageUrl" select="concat('http://',$url_HTTP_HOST,$url_PATH_INFO)" />
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="nowrap">Title</th>
<th class="ms-vh" nowrap="nowrap">Description</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<a href="/{@FileDirRef}/DispForm.aspx?ID={@ID}&Source={$CurrentPageUrl}" target="_blank"><xsl:value-of select="@Title" /></a></td>
<td class="ms-vb">
<xsl:value-of select="@Description"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet> </Xsl>
</WebPartPages:DataFormWebPart>
</ZoneTemplate></WebPartPages:WebPartZone></td>
</tr>
</table>
</asp:Content></tr>
</table>
Adding a content database using PowerShell in SharePoint 2010
Adding a content database using PowerShell in SharePoint 2010
To attach an existing content database:
Mount-SPContentDatabase "<ContentDb>" –DatabaseServer "<DbServer>"
–WebApplication http://WebapplicationName
<ContentDb> is the content database to be attached.
<DbServer> is the name of the database server.
http://WebapplicationName is the name of the Web application to which
the content database is being attached.
To detach a content database:
Dismount-SPContentDatabase "<ContentdBName>"
Where is the name of the content database.
To attach an existing content database:
Mount-SPContentDatabase "<ContentDb>" –DatabaseServer "<DbServer>"
–WebApplication http://WebapplicationName
<ContentDb> is the content database to be attached.
<DbServer> is the name of the database server.
http://WebapplicationName is the name of the Web application to which
the content database is being attached.
To detach a content database:
Dismount-SPContentDatabase "<ContentdBName>"
Where is the name of the content database.
How to list all the commands in PowerShell ?
Get-Command * commands gets you all the Powershell commands.
Permissions for Windows PowerShell - SPShellAdmin
Permissions for Windows PowerShell - SPShellAdmin
In order to use Windows PowerShell for SharePoint 2010 Products, a
user must be a member of the SharePoint_Shell_Access role on the
configuration and content database. In addition to this, the user must
also be a member of the WSS_ADMIN_WPG local group on the computer
where SharePoint 2010 Products is installed.
To add a user as SharePoint_Shell_Access on the SharePoint database
use the below powershell cmdlet :
Add-SPShellAdmin
Please Note that to run the above cmdlet you must have
* Membership in the securityadmin fixed server role on the SQL Server instance
* Membership in the db_owner fixed database role on all affected databases
* and local administrative permission on the local computer.
In addition to above some important things to Note:
* The user gets added to the WSS_Admin_WPG group on all Web servers
when the user is added to the SharePoint_Shell_Access role.
* If the target database does not have a SharePoint_Shell_Access role,
the role is automatically created.
* If you use the database parameter, the user is added to the role on
the farm configuration database, the Central Administration content
database, and the specified database. Using the database parameter is
the preferred method because most of the administrative operations
require access to the Central Administration content database. The
cmdlet is something like below :
Add-SPShellAdmin -UserName Domainname\User -database {Database GUID}
In order to use Windows PowerShell for SharePoint 2010 Products, a
user must be a member of the SharePoint_Shell_Access role on the
configuration and content database. In addition to this, the user must
also be a member of the WSS_ADMIN_WPG local group on the computer
where SharePoint 2010 Products is installed.
To add a user as SharePoint_Shell_Access on the SharePoint database
use the below powershell cmdlet :
Add-SPShellAdmin
Please Note that to run the above cmdlet you must have
* Membership in the securityadmin fixed server role on the SQL Server instance
* Membership in the db_owner fixed database role on all affected databases
* and local administrative permission on the local computer.
In addition to above some important things to Note:
* The user gets added to the WSS_Admin_WPG group on all Web servers
when the user is added to the SharePoint_Shell_Access role.
* If the target database does not have a SharePoint_Shell_Access role,
the role is automatically created.
* If you use the database parameter, the user is added to the role on
the farm configuration database, the Central Administration content
database, and the specified database. Using the database parameter is
the preferred method because most of the administrative operations
require access to the Central Administration content database. The
cmdlet is something like below :
Add-SPShellAdmin -UserName Domainname\User -database {Database GUID}
If you need going to install a webpart or any custom solution in SharePoint 2010 using PowerShell What permissions do you need?
If you need going to install a webpart or any custom solution in SharePoint 2010 using PowerShell What permissions do you need?
In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration and content database. In addition to this, the user must
also be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed.
In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration and content database. In addition to this, the user must
also be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed.
Where is Powershell located in sharePoint ?
On the Start menu, click All Programs -> Click Microsoft SharePoint 2010 Products -> Click SharePoint 2010 Management Shell.
Can you Create PowerShell scripts for deploying components in SharePoint ?
If you are creating a webpart with VS 2010 then you can deploy it using ctrl + f5. However, to activate the webpart feature you can write a powershell script (.ps1) and execute it after dpeloyment.
What are CMDLets?
Windows PowerShell introduces the concept of a cmdlet which are simple build in commands, written in a .net language like C# or VB.
How is Windows Powershell different from Stsadm ?
Unlike stsadm, which accept and return text, Windows PowerShell is built on the Microsoft .NET Framework and accepts and returns .NET Framework objects. In addition to that it also gives you access to the file system on the computer so that you can access registry,digital signature certificate etc..
What is windows PowerShell?
Windows PowerShell is a new Windows command-line shell designed especially for system administrators. In the SharePoint administration context, Windows PowerShell is another administration tool that supersedes the existing Stsadm.exe.
SharePoint 2010 Windows PowerShell Commands Part2
Some more PowerShell Commands
Site Collection Commands
Create Site Collection :
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite -Url "" -OwnerAlias "" -Template $template
Delete Site Collection :
Remove-SPSite -Identity "URL of site Collection" -GradualDelete
Change Site collection Quotas :
Set-SPSite -Identity "SiteCollection Url" -MaxSize Quota
Add site Collection Administrators :
Set-SPSite -Identity "" -SecondaryOwnerAlias ""
Lock or unlock a site collection :
Set-SPSite -Identity "Site Collection Url" -LockState ""
is one of the following vales :
# Unlock: To unlock the site collection and make it available to users.
# NoAdditions: To prevent users from adding new content to the site collection. Updates and deletions are still allowed.
# ReadOnly: To prevent users from adding, updating, or deleting content.
# NoAccess: To prevent access to content completely. Users who attempt to access the site receive an access-denied message.
Create a site :
New-SPSite "http://sitecollection/sites/ Subsite -OwnerAlias "DOMAIN\UserName" –Language 1033
Site Collection Commands
Create Site Collection :
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite -Url "" -OwnerAlias "" -Template $template
Delete Site Collection :
Remove-SPSite -Identity "URL of site Collection" -GradualDelete
Change Site collection Quotas :
Set-SPSite -Identity "SiteCollection Url" -MaxSize Quota
Add site Collection Administrators :
Set-SPSite -Identity "" -SecondaryOwnerAlias ""
Lock or unlock a site collection :
Set-SPSite -Identity "Site Collection Url" -LockState ""
is one of the following vales :
# Unlock: To unlock the site collection and make it available to users.
# NoAdditions: To prevent users from adding new content to the site collection. Updates and deletions are still allowed.
# ReadOnly: To prevent users from adding, updating, or deleting content.
# NoAccess: To prevent access to content completely. Users who attempt to access the site receive an access-denied message.
Create a site :
New-SPSite "http://sitecollection/sites/
SharePoint 2010 Windows PowerShell Commands - Part1
To Open the Windows PowerShell Session :
1. On the Start menu, click All Programs.
2. Click Microsoft SharePoint 2010 Products.
3. Click SharePoint 2010 Management Shell
Note : You should have SharePoint_Shell_Access role on the configuration database and you should be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint Server 2010 is installed.
Some of the Common Commands and Operations are:
Create Web Application Variable
$webapp = Get-SPWebApplication "http://WebapplicationUrl"
Create SharePoint Site Variable (Instance of SPSite)
$siteurl = "http://MySharePointSite"
$Oursite=new-object Microsoft.SharePoint.SPSite($ siteurl)
Here we have created a variable Oursite, which contains an instance of type SPSite. Now you can use it to display all webs in the site collection.
$Oursite.AllWebs more // List all Webs in the Site
Create Service Application Variable
$spapp = Get-SPServiceApplication -Name " ServiceApplicationDisplayName"
Create a Webapplication:
New -SPWebApplication -ApplicationPoolName <Name of the application pool> -Name <Name of the new Web application> [ -Port <Port on which the Web application can be accessed>] [-HostHeader <Valid URL assigned to the Web application that must correlate to the alternate access mapping configuration>] [-URL <Load-balanced URL for the Web application>][ -ApplicationPoolAccount <User account that this application pool will run as>]
Delete WebApplication
Create\Delete a Site Collection:
Create a Site collection:
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite –Url "<URL for the new site collection>" –OwnerAlias "<domain\user>" –Template $template
Here $template is a Variable to store the type of template we want to use while creating a site collection.
Delete a Site Collection:
Remove-SPSite –Identity <URL> –GradualDelete
Here <URL > is a site Collection Url .
Back\Restore a content database
To Backup :
Backup -SPFarm -Directory <Backup folder> -BackupMethod -Item <Content database name> [-Verbose]
Backup folder - is a folder to save your backup.
BackupMethod – Can Specify between Full or Differential.
To Restore:
Restore -SPFarm -Directory <Backup folder> -RestoreMethod Overwrite -Item <Content database name> [-BackupId] [-Verbose]
If you don’t know the BackupID you can display all the backups using the below command and get the GUID of the Backup.
Get-SPBackupHistory -Directory <Backup folder>
You can check all the Backup-Restore Operations Here
Deploy WebPart Soluiton Package
Install -SPWebPartPack -LiteralPath "PathToCABorwspFile" -Name "NameOFWebPart"
PathToCABorwspFile- is the full path to the CAB file that is being deployed.
NameOFWebPart- is the name of the Web Part that is being deployed.
Install Activate and Deactivate Feature using Windows Powershell
Install Feature :
$MyFeatureId = $(Get -SPFeature -limit all where {$_.displayname -eq "myfeatureName"}).Id
Install -SPFeature $MyFeatureId
Activate\Enable Feature :
$singleSiteCollection = Get -SPSite -Identity http:// MySingleSiteCollectionURL
Enable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL
Deactivate\Disable Feature :
$singleSiteCollection = Get-SPSite -Identity http:// MySingleSiteCollectionURL
Disable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL
Command TO List all the PowerShell Commands Get-Command –PSSnapin “Get-Command –PSSnapin “Microsoft.SharePoint. PowerShell” format-table name > C:\SP2010_PowerShell_Commands. txt
1. On the Start menu, click All Programs.
2. Click Microsoft SharePoint 2010 Products.
3. Click SharePoint 2010 Management Shell
Note : You should have SharePoint_Shell_Access role on the configuration database and you should be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint Server 2010 is installed.
Some of the Common Commands and Operations are:
Create Web Application Variable
$webapp = Get-SPWebApplication "http://WebapplicationUrl"
Create SharePoint Site Variable (Instance of SPSite)
$siteurl = "http://MySharePointSite"
$Oursite=new-object Microsoft.SharePoint.SPSite($
Here we have created a variable Oursite, which contains an instance of type SPSite. Now you can use it to display all webs in the site collection.
$Oursite.AllWebs more // List all Webs in the Site
Create Service Application Variable
$spapp = Get-SPServiceApplication -Name "
Create a Webapplication:
New -SPWebApplication -ApplicationPoolName <Name of the application pool> -Name <Name of the new Web application> [ -Port <Port on which the Web application can be accessed>] [-HostHeader <Valid URL assigned to the Web application that must correlate to the alternate access mapping configuration>] [-URL <Load-balanced URL for the Web application>][ -ApplicationPoolAccount <User account that this application pool will run as>]
Delete WebApplication
Remove-SPWebApplication –identity -URL <http://sitename> -ConfirmCreate\Delete a Site Collection:
Create a Site collection:
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite –Url "<URL for the new site collection>" –OwnerAlias "<domain\user>" –Template $template
Here $template is a Variable to store the type of template we want to use while creating a site collection.
Delete a Site Collection:
Remove-SPSite –Identity <URL> –GradualDelete
Here <URL > is a site Collection Url .
Back\Restore a content database
To Backup :
Backup -SPFarm -Directory <Backup folder> -BackupMethod -Item <Content database name> [-Verbose]
Backup folder - is a folder to save your backup.
BackupMethod – Can Specify between Full or Differential.
To Restore:
Restore -SPFarm -Directory <Backup folder> -RestoreMethod Overwrite -Item <Content database name> [-BackupId] [-Verbose]
If you don’t know the BackupID you can display all the backups using the below command and get the GUID of the Backup.
Get-SPBackupHistory -Directory <Backup folder>
You can check all the Backup-Restore Operations Here
Deploy WebPart Soluiton Package
Install -SPWebPartPack -LiteralPath "PathToCABorwspFile" -Name "NameOFWebPart"
PathToCABorwspFile- is the full path to the CAB file that is being deployed.
NameOFWebPart- is the name of the Web Part that is being deployed.
Install Activate and Deactivate Feature using Windows Powershell
Install Feature :
$MyFeatureId = $(Get -SPFeature -limit all where {$_.displayname -eq "myfeatureName"}).Id
Install -SPFeature $MyFeatureId
Activate\Enable Feature :
$singleSiteCollection = Get -SPSite -Identity http://
Enable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL
Deactivate\Disable Feature :
$singleSiteCollection = Get-SPSite -Identity http://
Disable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL
Command TO List all the PowerShell Commands Get-Command –PSSnapin “Get-Command –PSSnapin “Microsoft.SharePoint.
Check in documents with Powershell SharePoint 2010
A simple script shared at @ http://secretsofsharepoint.com/cs/ site for Checking in the documents in a document library using a powershell script.
function CheckInDocument([string]$url)
{
$spWeb = Get-SPWeb $url
$getFolder = $spWeb.GetFolder(“Shared Documents”)
$getFolder.Files | Where { $_.CheckOutStatus -ne “None” } | ForEach
{
Write-Host “$($_.Name) is Checked out To: $($_.CheckedOutBy)”
$_.CheckIn(“Checked In By Administrator”)
Write-Host “$($_.Name) Checked In” -ForeGroundColor Green
}
$spWeb.Dispose()
}
{
$spWeb = Get-SPWeb $url
$getFolder = $spWeb.GetFolder(“Shared Documents”)
$getFolder.Files | Where { $_.CheckOutStatus -ne “None” } | ForEach
{
Write-Host “$($_.Name) is Checked out To: $($_.CheckedOutBy)”
$_.CheckIn(“Checked In By Administrator”)
Write-Host “$($_.Name) Checked In” -ForeGroundColor Green
}
$spWeb.Dispose()
}
Here’s an example on running the function:
CheckInDocument http://SP
SharePoint 2010 PowerShell Permissions Explained
SharePoint 2010 has increased flexibility for administrative privileges of command line operations. The end result is that there is a bit more complexity in setting up your administrative privileges, so I wanted to create a post to try and clear up administration permissions for SharePoint 2010.
Foremost, please keep in mind that I’m going to discuss the minimum required privileges for each role—so there are lots of additional configurations; this is the just bare requirements.
First we need to talk about Central Administration, as the different permissions often lead to confusion. To access Central Administration, you need to be a Farm Administration—aka, a member of the “Farm Administrators Group”. This is really a UI only permission (I recommend you think of “Farm Adminstration Privs” as “The ability to use Central Admin”. The reason for this is that Farm Administrators have the ability to run operations via-the Central Administation Web Application; keep in mind that no operation actually runs against the Configuration Database as the user but rather as the App Pool account for the Web App.
With STSADM and PowerShell, all commands are run as the user who executes the command (not through the Central Admin Web Application). The good part about this is that any command can be run from any machine (no CA required), but this means that the user themselves needs the proper permissions. With STSADM, the user required Box, Farm, and SQL permissions—way too much to run a truly “Least Privs” environment. With 2010 there is the flexibility to only require PowerShell & SQL permissions*.
*Note: Box permissions are required for a small subset of commands that touch the Windows filesystem or registry. Also, Box and SQL are required for all “setup” operations.
On that note, there are only two requirements for most commands. The user must be:
· A member of the WSS_ADMIN_WGP group (this is a Windows Group on the machine the user is executing commands on)
· A member of the “SharePoint_Shell_Access” role on the configuration database (this is a SQL Role)
To simplify the management of these roles we have created a set of PowerShell commands (noun is “SPShellAdmin”) to add and remove Shell Administrators. You’ll notice that the commands allow you to designate a specific database, this is because the “Shell Admin” role by default only gives the user access to the Configuration Database; the shell admin must be given access to each individual service and content database they are “allowed to manipulate” (i.e.: to delete a content database, the user must be a shell admin on that database).
*IMPORTANT: The Shell Admin commands in SharePoint 2010 Beta do not fully setup these roles; you need to add the WSS_ADMIN_WGP role manually.
Please keep in mind that each command is just running object model, so additional permissions may be required for specific commands. For example, you may need Service Application permissions to run commands against a certain service application.
Hopefully I’ve made permissions a little easier to understand—but if you’ve still got questions, put them in the comments section below.
Run a SharePoint PowerShell Backup Script using Windows Scheduler
SharePoint administrators need to run regular backups using PowerShell, the STSADM tool or in Central Administration. There is no "built in" way to automate these backups. Wouldn't it be great to devise a method to automate these jobs.
The solution is just to create a batch file that can execute a PowerShell script, and then launch it from the Windows Task Scheduler.
PowerShell Command to Backup SharePoint Site Collection
backup-spsite -identity http://moss2010/ -path D:\Backup\Backup.bak
So, you can use the backup-spsite command to do site backup (the example shows http:// moss2010 /). The following script will start a full backup to D:\backup where you can send a site collection URL and backup file name as a parameter to the PowerShell Script.
$args[0] = http://moss2010/ [Source site location URL] $args[1] = D:\backup\backup_site.bak [Destination path] Create Windows PowerShell script
Add-PSSnapin Microsoft.SharePoint.PowerShell backup-spsite -identity $args[0] -path $args[1] -forceSave it as PowerShell D:\Scripts\BackupSPSite.ps1Create Batch Script to execute PowerShell script
@echo offSET SOURCE_SITE=http://moss2010/ SET DEST=D:\backup\Backup_site.bakecho "backup Started at" %DATE% >> D:\backup\Log.txtpowershell -command D:\Scripts\BackupSPSite.ps1 %SOURCE_SITE% %DEST%echo "Backup completed successfully at %DEST%" on %DATE% >> D:\backup\Log.txt@echo onSave it as Batch file D:\Scripts\BackupSPSite.bat. Now you have to run this script. Run Batch Script to execute PowerShell script
- Run batch script to check successful backup and log creation at D:\backup.
- Now run it from the Windows Task Scheduler. In the Task Scheduler, the account needs to be set with admin permissions to run it properly.
So now you can automate your daily backup of a SharePoint Site. You can also run an entire Farm backup just by using the following command in a PowerShell Script (i.e. D:\Scripts\BackupSPSite.ps1)Get files from document library Silverlight client object model
Get files from document library Silverlight client object model
Here is a detailed code snippet for creating a silverlight applictaion that will display all the files\documents from a document library in a webpart using silverlight Client Object model.
To begin with
1. In Visual Studio 2010 create a new Blank Solution. Select .NET Framework 3.5.
2. Next, from the File menu open click on Add -> New Project.
3. In the New Project dialog box, expand the Installed Templates left hand menu to Visual C# -> Silverlight, and choose the Silverlight Application project type in the project type list in the middle section of the screen. Make sure that you have .NET Framework 3.5 selected. Click Ok to continue on Silverlight Application dialog box.
4. Next, add the required references to the Silverlight client object model. To do this browse to “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\ LAYOUTS\ClientBin” and select Microsoft.SharePoint. ClientSilverlight.dll and Microsoft.SharePoint.Client. Silverlight.Runtime.dll
5. In the solution explorer open the App.xaml.cs and add the following references to the top of the page.
using Microsoft.SharePoint.Client;
using System.Threading;
6. Next in the same file App.xaml.cs, under Applictaion_Startup method add the below to get the refrence to the current sharepoint site and to ensure that we are in sync with the current SharePoint site.
ApplicationContext.Init(e. InitParams, Synchronizationcontext. Current);
7. Next, lets open up our MainPage.xaml and Add two StackPanels under the existing grid.
<StackPanel Orientation=”Vertical” VerticalAlignment=”Top”>
<StackPanel Name=”mypanel” />
</StackPanel>
8. Now, Open MainPage.xaml.cs and add the following using statements to the top of the file:
using Microsoft.SharePoint.Client;
9. Next, add the following code to get all the files from your SharePoint document library in the silverlight webpart.
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
ClientContext clientCtx;
Microsoft.SharePoint.Client. List docs;
int FileCounter= 0;
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
clientCtx = new ClientContext( ApplicationContext.Current. Url);
clientCtx.Load(clientCtx.Web);
clientCtx.Load(clientCtx.Web. Lists);
docs = clientCtx.Web.Lists. GetByTitle(“My Documents”);
clientCtx.Load(docs);
clientCtx.Load(docs. Rootfolder);
clientCtx.Load(docs. Rootfolder.Files);
clientCtx.ExecuteQueryAsync( loadSiteData, null); // We will move to loadSiteData method on success
}
void loadSiteData(Object sender, ClientRequestSucceededEventArg s e)
{
//This method starts on a background thread, but we need to work on UI to display our files Therefore we call Dispatcher.BeginInvoke() to perform the UI updating on the main thread
Dispatcher.BeginInvoke( addFiles);
}
void addFiles()
{
foreach (File doc in docs.Rootfolder.Files)
{
clientCtx.Load(doc);
clientCtx.ExecuteQueryAsync( addFiletoUI, null); // We will move to loadSiteData method on success
}
}
void addFiletoUI(Object sender, ClientRequestSucceededEventArg s e)
{
Dispatcher.BeginInvoke( addFile);
}
void addFile()
{
string filename = docs.Rootfolder.Files[ FileCounter].Name;
string fileUrl = docs.Rootfolder.Files[ FileCounter]. ServerRelativeUrl;
HyperlinkButton fLink= new HyperlinkButton();
fLink.Content = filename;
fLink.NavigateUri = new Uri(fileUrl , UriKind.Relative);
mypanel.Children.Add(fLink);
FileCounter++;
}
}
10. Build and deploy the webpart.
11. Goto SharePoint site and add a silverlight webpart. Point the webpart to “”/_layouts/ClientBin/ YourSilverlightApp_Name.xap” and your Done! yeh!
To begin with
1. In Visual Studio 2010 create a new Blank Solution. Select .NET Framework 3.5.
2. Next, from the File menu open click on Add -> New Project.
3. In the New Project dialog box, expand the Installed Templates left hand menu to Visual C# -> Silverlight, and choose the Silverlight Application project type in the project type list in the middle section of the screen. Make sure that you have .NET Framework 3.5 selected. Click Ok to continue on Silverlight Application dialog box.
4. Next, add the required references to the Silverlight client object model. To do this browse to “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\
5. In the solution explorer open the App.xaml.cs and add the following references to the top of the page.
using Microsoft.SharePoint.Client;
using System.Threading;
6. Next in the same file App.xaml.cs, under Applictaion_Startup method add the below to get the refrence to the current sharepoint site and to ensure that we are in sync with the current SharePoint site.
ApplicationContext.Init(e.
7. Next, lets open up our MainPage.xaml and Add two StackPanels under the existing grid.
<StackPanel Orientation=”Vertical” VerticalAlignment=”Top”>
<StackPanel Name=”mypanel” />
</StackPanel>
8. Now, Open MainPage.xaml.cs and add the following using statements to the top of the file:
using Microsoft.SharePoint.Client;
9. Next, add the following code to get all the files from your SharePoint document library in the silverlight webpart.
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
ClientContext clientCtx;
Microsoft.SharePoint.Client.
int FileCounter= 0;
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
clientCtx = new ClientContext(
clientCtx.Load(clientCtx.Web);
clientCtx.Load(clientCtx.Web.
docs = clientCtx.Web.Lists.
clientCtx.Load(docs);
clientCtx.Load(docs.
clientCtx.Load(docs.
clientCtx.ExecuteQueryAsync(
}
void loadSiteData(Object sender, ClientRequestSucceededEventArg
{
//This method starts on a background thread, but we need to work on UI to display our files Therefore we call Dispatcher.BeginInvoke() to perform the UI updating on the main thread
Dispatcher.BeginInvoke(
}
void addFiles()
{
foreach (File doc in docs.Rootfolder.Files)
{
clientCtx.Load(doc);
clientCtx.ExecuteQueryAsync(
}
}
void addFiletoUI(Object sender, ClientRequestSucceededEventArg
{
Dispatcher.BeginInvoke(
}
void addFile()
{
string filename = docs.Rootfolder.Files[
string fileUrl = docs.Rootfolder.Files[
HyperlinkButton fLink= new HyperlinkButton();
fLink.Content = filename;
fLink.NavigateUri = new Uri(fileUrl , UriKind.Relative);
mypanel.Children.Add(fLink);
FileCounter++;
}
}
10. Build and deploy the webpart.
11. Goto SharePoint site and add a silverlight webpart. Point the webpart to “”/_layouts/ClientBin/
How do you access ECMAScript object model API’s
The ECMAScript library is available in a number of JS files in the LAYOUTS folder. The main file among number of .js files is SP.js. When you include this file in the APSX page using a ScriptLink control, all other required JS files are loaded automatically. By linking SP.js to your page, the SP namespace gets registered. SP is the SharePoint namespace that contains all objects. For debugging purposes every js file also has a ‘debug’ equivalent in the same folder.
Infopath 2010 form drop-down list change event get data programmatically
Infopath 2010 form drop-down list change event get data programmatically
A short code snippet to get the data from a datasource on change event of a drop-down list in Infopath 2010 form.
In the code below the method InternalStartup() is called to register the event change for the dropdown and the method mydropdown_Changed() is called to access the actual datasource “MyDATASOURCE” for retrieving the values for Field1 or sharepoint Title column from the sharepoint list datasource(MyDATASOURCE).
The parameter passed to the Datasource via the webservice is ID of the drop-down item.
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System;
using System.Xml;
using System.Xml.XPath;
namespace Getdatanamespace
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.XmlEvents["/my:myform/my:table1/my:mydropdown"].Changed += new XmlChangedEventHandler(mydropdown_Changed);
}
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.XmlEvents["/my:myform/my:table1/my:mydropdown"].Changed += new XmlChangedEventHandler(mydropdown_Changed);
}
public void mydropdown_Changed(object sender, XmlEventArgs e)
{
{
XPathNavigator form = MainDataSource.CreateNavigator();
// Set parameter for web service request and query connection
DataSources["MyDATASOURCE"].CreateNavigator().SelectSingleNode(“/dfs:myFields/dfs:queryFields/q:SharePointListItem_RW/q:ID”,NamespaceManager).SetValue(e.NewValue); ->> sending the ID as a parameter to the webservice call which will access the datasource
DataSources["MyDATASOURCE"].CreateNavigator().SelectSingleNode(“/dfs:myFields/dfs:queryFields/q:SharePointListItem_RW/q:ID”,NamespaceManager).SetValue(e.NewValue); ->> sending the ID as a parameter to the webservice call which will access the datasource
DataSources["MyDATASOURCE"].QueryConnection.Execute();
// Create navigator on web service response
XPathNavigator resultnav = DataSources["MyDATASOURCE"].CreateNavigator();
XPathNavigator resultnav = DataSources["MyDATASOURCE"].CreateNavigator();
// Set fields with values from web service response
XPathNavigator Field1 = form.SelectSingleNode(“/my:myform/my:table1/my:field1″, NamespaceManager);
Field1.SetValue(resultnav.SelectSingleNode(“/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title”,NamespaceManager).Value);
}
XPathNavigator Field1 = form.SelectSingleNode(“/my:myform/my:table1/my:field1″, NamespaceManager);
Field1.SetValue(resultnav.SelectSingleNode(“/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title”,NamespaceManager).Value);
}
}
}
}
Subscribe to:
Posts (Atom)