Monday 27 February 2012

How to Identify the User in Sharepoint Through C# Code


string strUser = txtName.Text.Trim();

SPPrincipalInfo principalInfo = SPUtility.ResolveWindowsPrincipal(mySite.WebApplication, strUser, SPPrincipalType.All, false);

if (principalInfo != null)
{
    SPUser user = myWeb.EnsureUser(strUser);
    ...
    ...
    ...
}

NameSpace:
using Microsoft.SharePoint.Utilities;

Sunday 19 February 2012

How to Get Backup, Restore Site Collection & Deploy the Wsp File



Step 0: we want to run the following command in shell window(step 2).
Backup-SPSite -Identity "site collection url" -Path "bak file location"
Example:
Backup-SPSite -Identity "http://SITENAME/sites/ab" -Path "C:/AB.bak"

Step 1: we want to create the site collection in the following way;
             Start à All Programs à Microsoft Office SharePoint Products 2010 à SharePoint 2010 Central Administration à Create Site Collections à Choose web Application Port(80),  Enter title, choose(/sites/) and enter web site address and then choose the template selection(Team Site).

Step 2: we want to open the Shell window in the following way;
Start à All Programs à Microsoft Office SharePoint Products 2010 à SharePoint 2010 Management Shell (Run as administrator).

Step 3: Restore the existing site collection to new site collection using the following  command;
Restore-SPSite –identity "site collection url" -Path "bak file with location" –force
The above command copy & paste in shell window (step 2) and then enter.
Example;
Restore-SPSite –identity "http://SITENAME/sites/ab" -Path "D:/AB.bak" –force

Step 4: If we want to deploy the first time (wsp file), follow the step 5.1 otherwise (next time) follow the step 5.2.  

Step 5: 1. We want to keep the wsp file in server location then following command copy & paste in shell window (step 2) and then enter one by one.
A.      People Leader web part
i. Add-SPSolution -LiteralPath "wsp file location"
ii. Install-SPSolution -Identity wsp file name -WebApplication site url –GACDeployment
B.      Individual Contributor web part
i. Add-SPSolution -LiteralPath " wsp file location "
ii. Install-SPSolution -Identity wsp file name -WebApplication site url –GACDeployment
Example;
C.      People Leader web part
i. Add-SPSolution -LiteralPath "C:\spbackup\ABbank\ABC.wsp"
ii. Install-SPSolution -Identity ABC.wsp -WebApplication http://SITENAME/ –GACDeployment
D.      Individual Contributor web part
i. Add-SPSolution -LiteralPath "C:\spbackup\ABbank\DEF.wsp"
ii. Install-SPSolution -Identity DEF.wsp -WebApplication http://SITENAME/ –GACDeployment


Step 5: 2. We want to do the following things;
Start à All Programs à Microsoft Office SharePoint Products 2010 à SharePoint 2010 Central Administration à System Settings à Manage Farm Solutions
It is showing the list of wsp files, we want to click our required wsp file then click “Retract Solution” after that we will wait until the status change from deployed to not deployed. There after we want to click the same wsp file then click “Remove Solution” after that we will wait until the file removed.
Then follow the step 5.1.

Step 6: We want to Add or Modify the item(new site collection url) in Site URL List.
Example;
http://SITENAME.com/sites/ab

Step 7: Finished.

Friday 10 February 2012

How to deploy & redeploy the Visual web part wsp file in Sharepoint ?

First time Deployment :

1. We want to Copy & Paste in any Server location.

2. We want to open(Run as Administrator) the Sharepoint 2010 Management Shell Command Window in the following way :-

 Start --> All Program --> MicroSoft Sharepoint 2010 products --> Sharepoint 2010 Management Shell

3. We want to copy & paste the following command in shell window(PS C:\User\Administrator>)

Add-SPSolution -LiteralPath "wsp file local location(server)"

Example: 
Add-SPSolution -LiteralPath "C:\spbackup\ABbank\ABC.wsp"

4. Then We want to copy & past the following command in the same shell window

Install-SPSolution -Identity wsp file name -WebApplication site url –GACDeployment

Example:
Install-SPSolution -Identity ABC.wsp -WebApplication http://SITENAME/ –GACDeployment

Next time Deployment :

1. We want to open the Manage Farm Solutions Window in the following way :-

 Start --> All Program --> MicroSoft Sharepoint 2010 products --> Sharepoint 2010 Central Administration --> System Settings --> Manage Farm Solutions

2. then click the Existing wsp file

3. then click the Retract Solution link then Click OK

4.  then wait for the status change from retracting to Not Deployed

5. then click the same wsp file & then click "Remove Solution"

6. then wait untile the wsp file removed

7. then do step 2

8. then click the remove solution link

9. After that follow the above First time Deployment :













How to Create Visual Studio 2010 web part

1. Create Visual web part project in Visual studio 2010

2. Then enter your Site Collection Url in Sharepoint customization wizard
     Ex: http://SITENAME/sites/dumy/

3. Choose Deploy as a farm solution in Sharepoint customization wizard

4. Finish








   



Thursday 9 February 2012

How to Change the link as a Image in sharepoint designer web part ?

1. We want to select the binded url in web part

2. Select the following image hyperlink option link

3. Then popup the following message




4.Select Yes and then choose the site location image and then edit the web part the following source code

  
<xsl:choose>
<xsl:when test="$desc=''">
<xsl:value-of select="$url" /></xsl:when>
<xsl:otherwise>
<a href="{$url}" ></a></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>

5.Then change the following way the above code

<xsl:choose>
<xsl:when test="$desc=''">
<xsl:value-of select="$url" /></xsl:when>
<xsl:otherwise>
<xsl:variable name="positeurl" select="substring-before($desc, '/Purchase%20Order')"/>
<xsl:variable name="positeimgurl" select="concat($positeurl, '/Style%20Library/Images/img-icon-discuss.png')"/>
<a href="{$url}" ><img alt="" src="{$positeimgurl}" border="0" /></a></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>

6. Save & Close it.