Sunday, October 30, 2011

Create Document Library in sharepoint site Using Powershell

Leave a Comment
Execute following script in powershell to create document library in SharePoint site.

PS > $site = Get-SPSite("Site URL"); 
         $web =  $site.OpenWeb( );
         $template = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary;
         $web.Lists.Add("TestDocumentLibrary","Document Library Description",$template);
         $web.Update( );


Cheers !


Read More...

Delete List from SharePoint Portal through PowerShell

Leave a Comment
Execute following script in powershell to delete list from SharePoint Portal

PS> $site = Get-SPSite("Site URL");
        $web = $web.OpenWeb( );
        $list = $web.Lists["ListName"];
        $list.Delete( );
        $web.Update( );

Press Enter and List specified here will be deleted from SharePoint list.

Cheers !
Read More...

Friday, October 28, 2011

Create SPList through Powershell

Leave a Comment
Scenario : Create List in SharePoint through PowerShell


Execute following script in PowerShell


PS > $site = Get-SPSite("SPSiteUrl")
PS > $web = $site.OpenWeb()
PS > $listcollection = $web.Lists
PS > $template = [Microsoft.SharePoint.SPListTemplateType]::GenericList
PS > $newid = $listcollection.Add("MYList","MyList Description",$template);
PS > $newlist = $web.Lists["MYList"];
PS > $newlist.OnQuickLaunch = "True"
PS > $newlist.Update();
Read More...

Thursday, October 27, 2011

Powershell : Get-SPSite throws not recognized error

5 comments

Scenario : Get SPSite object in PowerShell 

While initializing SPSite objet in powershell, I got this error :

 The term ‘Get-SPSite’ is not recognized as the name of cmdlet, function, script file, or operable program

To resolve this issue fire this in powershell.

Add-PSSnapin Microsoft.SharePoint.Powershell

Check article here http://technet.microsoft.com/en-us/library/dd347601.aspx , to find more information on Add-PSSnapin.
Read More...

Get value of Choice Field from SharePoint List

Leave a Comment

Scenario:  Get value from Choice Field of SharePoint list in windows console application

SPSite site = new SPSite("Full qualified Site Url”);
SPWeb web = site.OpenWeb();
SPList list = web.Lists["ListName"];

// Here it is assumed that you know item id. But you can use SPQuery object to get specific item from SharePoint list.
SPListItem item = list.GetItemById(1);

string value = item.GetFormattedValue("MyColumn");

Console.WriteLine(value);

Read More...

Tuesday, October 25, 2011

Show User “I Like It” data in Webpart

Leave a Comment

"I like it" data is referred using Microsoft.Office.Server.SocialData Namespace.

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server;
using Microsoft.Office.Server.SocialData;
using System.Text;
namespace ResearchProject.WebParts
{
    [ToolboxItemAttribute(false)]
    public class LikeWebpart : WebPart
    {
        protected override void CreateChildControls()
        {
            UserProfile profile = null;
            SPServiceContext serviceContext = SPServiceContext.Current;
            UserProfileManager profileManager = new UserProfileManager(serviceContext);

            profile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.RawSid);

            SocialTagManager socialmanager = new SocialTagManager(serviceContext);
            SocialTag[] tags = socialmanager.GetTags(profile);

            StringBuilder tagstring = new StringBuilder();
            foreach (SocialTag tag in tags)
            {
                if (tagstring.Length > 0)
                {
                    tagstring.Append(",");
                }
                tagstring.Append(tag.Title);
            }
            this.Controls.Add(new LiteralControl(tagstring.ToString()));
        }
    }
}
Read More...