Friday 10 October 2014

The Feature is not a Farm Level feature and is not found in site defined by - Could not enable Feature

All wsp's have a feature id. We could obtain the feature id of the deployed wsp using the following command.

get-SPFeature

Now search for the feature id of the wsp that you want to enable to a site.
This feature could be activated using the following command.

Enable-SPFeature -Identity FeatureId -URL SiteCollectionURL -Force -PassThru

Note:
FeatureId  Will be the feature id of the wsp 
SiteCollectionURL will be the url of the site in which the wsp has to be enabled.

Sunday 6 July 2014

Get current logged in user


    To get current logged in user for Sharepoint use this piece of code. You can use this code with custom forms where it gets the current logged in user name.


                        SPWeb getcurweb = SPControl.GetContextWeb(Context);
                        SPUser getcurlogeduser = getcurweb.CurrentUser;
                        string currentusername = getcurlogeduser.Name;



Wednesday 4 June 2014

Check if current user belongs to particular group


To check if the current user belongs to particular group use the following code.


SPGroup Administrator_Group = SP_Web.Groups["Administrator"];
bool is_Administrator_Group =  SP_Web.IsCurrentUserMemberOfGroup(Administrator_Group.ID);


Tuesday 11 March 2014

An unhandled exception occurred in the silverlight application sharepoint 2010



              When i try to create a new list or document library in my site, I came across this weird problem.




              The original problem is Silverlight application in sharepoint does not get connected to the Windows Communication Foundation. This dosent allow us to create a list or library in a site. This is just a security issue at server side  and could be resolved by following this procedure.                    


  1. Open Central Administration
  2. Select Application Management
  3. Select Manage Web Applications
  4. Select the Web Application where the error occurs
  5. In the ribbon, select General Settings
  6. In the Web Application General Settings dialog box, find Web Page Security Validation and select On 

This resolves the problem and now a new list or library could be created.                         


Thursday 6 March 2014

Create site in a new Content Database Sharepoint 2010


      whenever i tried to create a new site in the server it takes up only default content database. I was looking after to create a new site in a separate content database. Unfortunately when i try to create a new site it does not ask me an option to choose the content database that i would like to create the site.

img

I dig up and found that this could be achieved using powershell.

First create a content database using central administration.
To create,

  1)  Central Administration -> Application Management -> Manage Content Databases under Databases.




2) You can see a content database that is already available by default. Here you have to add a new content database. Click Add a Content database.




3) You could rename the database name. Provide appropriate name for your database. Click ok.




4) Now you could see a new content database is created.

  To create a new site in that particular created content database use this following script in posershell.


Powershell Command:

New-SPSite http://yourServerName/sites/YourSite -OwnerAlias "ServerAdministratorUserName" -ContentDatabase ContentDatabaseName -Name "SiteNametobeCreated" -Description "DescriptionabouttheSite" -Template "STS#0"

On successful creation of site over the created database, you will receive this created url.


Thursday 13 February 2014

Server Dependency error (Missing Feature)


          When we redeploy wsp files in sharepoint server, it will check for its previous version using the feature ID. The old versions feature id will not be available since wsp files has been removed. Though the files have been removed its id will be available in the server.

           It will throw an exception and this exception will be stored in the configuration section. When site content backup is restored this error transfers to the other server too. This exceptions can be removed by using power shell command.

          Go to the following location. Central Administration --> Monitoring --> Review Problems and Solutions under Health Analyzer. Under category configuration click Missing Server side dependencies. There you will find [Missing Feature] type. Now go to Sharepoint Power Shell. and do the following.

PowerShell Remove Features in SharePoint because of Health Issue For "Missing Feature"


Run The below power shell Method in SharePoint Management shell.

 function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
    [bool]$report = $false
    if ($ReportOnly) { $report = $true }
   
    $db.Sites | ForEach-Object {
       
        Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report
               
        $_ | Get-SPWeb -Limit all | ForEach-Object {
           
            Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
        }
    }
}
function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
    $feature = $obj.Features[$featId]
   
    if ($feature -ne $null) {
        if ($report) {
            write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
        }
        else
        {
            try {
                $obj.Features.Remove($feature.DefinitionId, $true)
                write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
            }
            catch {
                write-host "There has been an error trying to remove the feature:" $_
            }
        }
    }
    else {
        #write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
    }
}



To run only a report (-ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "Content_DBName" -FeatureId "e8389ec7-70fd-4179-a1c4-6fcb4342d7a0" –ReportOnly

To remove the feature from all sites, site collections in the db run (no -ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "Content_DBName" -FeatureId "8096285f-1473-45c7-85b7-f745e5b2cf29"  


   This will work only for [Missing Feature] issues.

Monday 3 February 2014

XSLT Conditional formatting for sharepoint 2013


<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" xmlns:o="urn:schemas-microsoft-com:office:office">
  <xsl:include href="/_layouts/xsl/main.xsl"/>
  <xsl:include href="/_layouts/xsl/internal.xsl"/>
  <xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow)]"/>
  <xsl:param name="dvt_apos">&apos;</xsl:param>
<xsl:template name="FieldRef_Hyperlink_URL_body.Details" ddwrt:dvt_mode="body" match="FieldRef[(@Format='Hyperlink') and @Name='Details']" mode="URL_body" ddwrt:ghost="">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="url" select="$thisNode/@*[name()=current()/@Name]" />
    <xsl:variable name="desc" select="$thisNode/@*[name()=concat(current()/@Name, '.desc')]" />
    <xsl:choose>
      <xsl:when test="$url=''">
        <xsl:if test="$desc=''">
          <xsl:value-of select="$desc"/>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
<xsl:when test="$desc=''">
              <xsl:value-of select="$url" /></xsl:when>
<xsl:otherwise>
<a href="{$url}"><img alt="Status" src="../../../Style Library/Images/img-icon-discuss.png" border="0" /></a>
</xsl:otherwise>
</xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

<xsl:template name="FieldRef_header.Approvers" ddwrt:dvt_mode="header" match="FieldRef[@Name='Approvers']" mode="header" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)" style="width: 81px">
      <xsl:attribute name="class">
        <xsl:choose>
          <xsl:when test="(@Type='User' or @Type='UserMulti') and ($PresenceEnabled='1')">ms-vh</xsl:when>
          <xsl:otherwise>ms-vh2</xsl:otherwise>
         </xsl:choose>
      </xsl:attribute>
      <xsl:call-template name="dvt_headerfield">
        <xsl:with-param name="fieldname">
          <xsl:value-of select="@Name"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtitle">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="displayname">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtype">
          <xsl:choose>
            <xsl:when test="@Type='Number' or @Type='Currency'">number</xsl:when>
            <xsl:otherwise>x:string</xsl:otherwise>
          </xsl:choose>
        </xsl:with-param>
      </xsl:call-template>
    </th>
  </xsl:template>
<xsl:template name="FieldRef_header.Document_x0020_Status" ddwrt:dvt_mode="header" match="FieldRef[@Name='Document_x0020_Status']" mode="header" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)" style="width: 191px">
      <xsl:attribute name="class">
        <xsl:choose>
          <xsl:when test="(@Type='User' or @Type='UserMulti') and ($PresenceEnabled='1')">ms-vh</xsl:when>
          <xsl:otherwise>ms-vh2</xsl:otherwise>
         </xsl:choose>
      </xsl:attribute>
      <xsl:call-template name="dvt_headerfield">
        <xsl:with-param name="fieldname">
          <xsl:value-of select="@Name"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtitle">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="displayname">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtype">
          <xsl:choose>
            <xsl:when test="@Type='Number' or @Type='Currency'">number</xsl:when>
            <xsl:otherwise>x:string</xsl:otherwise>
          </xsl:choose>
        </xsl:with-param>
      </xsl:call-template>
    </th>
  </xsl:template>
<xsl:template name="FieldRef_printTableCell_EcbAllowed.Approvers" match="FieldRef[@Name='Approvers']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="class" />
    <td style="width: 81px">
      <xsl:if test="@ClassInfo='Menu' or @ListItemMenu='TRUE'">
        <xsl:attribute name="height">100%</xsl:attribute>
        <xsl:attribute name="onmouseover">OnChildItem(this)</xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:call-template name="getTDClassValue">
          <xsl:with-param name="class" select="$class" />
          <xsl:with-param name="Type" select="@Type"/>
          <xsl:with-param name="ClassInfo" select="@ClassInfo"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="PrintFieldWithECB">
        <xsl:with-param name="thisNode" select="$thisNode"/>
      </xsl:apply-templates>
    </td>
  </xsl:template>
<xsl:template name="FieldRef_printTableCell_EcbAllowed.Document_x0020_Status" match="FieldRef[@Name='Document_x0020_Status']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" ddwrt:ghost="">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="class" />
    <td>
<xsl:attribute name="style">
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Draft in Progress'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Assigned to 3rd party Lawyer'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Assigned to 3rd Party Lawyer'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Approval in Progress'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Details) = 'Review in progress'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Review in progress'" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:cf_explicit="1">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Approver Rejected'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FF0000; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-rejected.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>

<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Reviewer Rejected'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FF0000; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-rejected.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Pending Signature'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: left center;</xsl:if>

<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Pending Signature'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>

<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Not Started'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FAAC32; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/img-icon-inprogress.png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Active'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-image: url(&apos;../../../Style Library/Images/img-icon-approved.png&apos;); background-repeat: no-repeat; background-position: right center; font-weight: bold; color: #56C553;</xsl:if>
<xsl:if test="normalize-space($thisNode/@Document_x0020_Status) = 'Over Due'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">color: #FF0000; font-weight: bold; background-image: url(&apos;../../../Style Library/Images/Overdue(2).png&apos;); background-repeat: no-repeat; background-position: right center;</xsl:if>

</xsl:attribute>

      <xsl:if test="@ClassInfo='Menu' or @ListItemMenu='TRUE'">
        <xsl:attribute name="height">100%</xsl:attribute>
        <xsl:attribute name="onmouseover">OnChildItem(this)</xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:call-template name="getTDClassValue">
          <xsl:with-param name="class" select="$class" />
          <xsl:with-param name="Type" select="@Type"/>
          <xsl:with-param name="ClassInfo" select="@ClassInfo"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="PrintFieldWithECB">
        <xsl:with-param name="thisNode" select="$thisNode"/>
      </xsl:apply-templates>
    </td>
  </xsl:template>
<xsl:template name="FieldRef_header.Details" ddwrt:dvt_mode="header" match="FieldRef[@Name='Details']" mode="header" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)" style="width: 69px">
      <xsl:attribute name="class">
        <xsl:choose>
          <xsl:when test="(@Type='User' or @Type='UserMulti') and ($PresenceEnabled='1')">ms-vh</xsl:when>
          <xsl:otherwise>ms-vh2</xsl:otherwise>
         </xsl:choose>
      </xsl:attribute>
      <xsl:call-template name="dvt_headerfield">
        <xsl:with-param name="fieldname">
          <xsl:value-of select="@Name"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtitle">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="displayname">
          <xsl:value-of select="@DisplayName"/>
        </xsl:with-param>
        <xsl:with-param name="fieldtype">
          <xsl:choose>
            <xsl:when test="@Type='Number' or @Type='Currency'">number</xsl:when>
            <xsl:otherwise>x:string</xsl:otherwise>
          </xsl:choose>
        </xsl:with-param>
      </xsl:call-template>
   
    </th>
  </xsl:template>
<xsl:template name="FieldRef_printTableCell_EcbAllowed.Details" match="FieldRef[@Name='Details']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="class" />
    <td style="width: 69px">
      <xsl:if test="@ClassInfo='Menu' or @ListItemMenu='TRUE'">
        <xsl:attribute name="height">100%</xsl:attribute>
        <xsl:attribute name="onmouseover">OnChildItem(this)</xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:call-template name="getTDClassValue">
          <xsl:with-param name="class" select="$class" />
          <xsl:with-param name="Type" select="@Type"/>
          <xsl:with-param name="ClassInfo" select="@ClassInfo"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="PrintFieldWithECB">
        <xsl:with-param name="thisNode" select="$thisNode"/>
      </xsl:apply-templates>
    </td>
  </xsl:template>
</xsl:stylesheet></Xsl>

Tuesday 7 January 2014

Default permission levels in Sharepoint 2013

SharePoint 2013 includes seven permission levels:

- View Only: It enables users to view application pages.

- Limited Access: It enables users to access shared resources and a specific asset. Limited Access cannot be edited or deleted.

- Read: It enables users to view pages and list items, and to download documents.

- Contribute: Contribute enables users to manage personal views, edit items and user information, delete versions in existing lists and document libraries, and add, remove, and update personal Web Parts.

- Edit: It enables users to manage lists.

- Design: Design permission level enables users to view, add, update, delete, approve, and customize items or pages in the website.

- Full Control: It enables users to have full control of the website.

Apart from this SharePoint 2013 also provides some permission levels to templates other than team site template. These are below:

- Restricted Read: This permission level is only for Publishing sites only. It enables View pages and documents.

- Approve: This permission level is only for Publishing sites only. It enables Edit and approve pages, list items, and documents.

- Manage Hierarchy: This permission level is only for Publishing sites only. Create sites; edit pages, list items, and documents, and change site permissions.

Thursday 2 January 2014

Deleting error webpart without using designer


          I was using a ReportViewerWebPart webpart at my home page. Sometimes during deployment this cause trouble that i could not open my home page since in some servers reports was not configured. I was resolving it using Sharepoint designer. I would open up my home page with sharepoint designer delete the webpart and now i could open my home page.

         Now i have found an alternate solution for this. We could use Web Part Page Maintenance for deleting this error web part. The solution is,

Procedure:

     Add the value ?Contents=1 at the end of your site.

     It now looks like http://yourservername/sites/yoursitename?Contents=1

     Hit Enter, that leads you to webpart maintenance page.

        
  The "Open on Page" shows error if that webpart contains error. you can select that particular webpart and delete it.

     Now the error webparts in homepage is deleted and the home page is displayed without the error webparts.