Wednesday, August 6, 2014

Adding Wiki Page in SharePoint Programmatically

Introduction

As we all know wiki page is one of the concept in SharePoint to add content at run time. Let's see how to add this wiki page programmatically.

Wiki Page 

At first, Create new SharePoint Project in Visual studio with one feature file. Then, Create an Event Receiver for feature. Paste the below code in FeatureActivated method.

  using (SPSite site = new SPSite(webUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Site Pages"];
                    web.AllowUnsafeUpdates = true;
                    SPFolder rootFolder = list.RootFolder;
                    SPFile wikiPage = SPUtility.CreateNewWikiPage(list, String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "your page name"));
                    SPListItem wikiItem = wikiPage.Item;
                    wikiItem["WikiField"] = "content";
                    wikiItem.Update();
                    web.AllowUnsafeUpdates = false;
                }
            }

Just deploy the solution in your site and activate the feature to see created Wiki page.



Happy Coding.. !!!!

Tuesday, August 5, 2014

Showing My Site's Newsfeed in SharePoint Web Application Programmatically

Introduction

 In My Site (SharePoint 2013), We have an option to track our activity using News Feed webpart. This webpart will show all the activities of logged in person in Mysite. Let see the note about Newsfeed webpart


NewsFeed

NewsFeed is the user's social hub where user can see the updates from people, documents, sites and tags which is followed by user. It displays the feeds of recent activities related to a user's specified interests. User can customize their interest by adding (Follow) / removing (Unfollow) colleagues, tags and documents.

This is short note about NewsFeed webpart. Let's see how we can integrate this into normal SharePoint site collection programmatically.

After the creation of farm solution using visual studio. Just add your sitepage under SitePages module.


Add Microsoft.SharePoint.Portal Reference


Then, Register portal dll in created sitepage.

<%@ Register TagPrefix="Portal" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Paste the MicroFeedwebpart at where you want to display it within page. This webpart is used to get the feeds which is in My Site Newsfeed

<Portal:MicroFeedWebPart runat="server" id="sfwNewssFeed" ChromeType="none"></Portal:MicroFeedWebPart>  

That's all. Deploy your solution in SP web application. Newsfeed will display in SitePage.


Monday, August 4, 2014

Configure User Profile in SharePoint Farm

Introduction

I am going to share an idea to configure the User profile in Farm solution. Let see

Web Application

At first, Create a new web application for My Site with "Mysite Host" site collection. This web application will be act as My site once all configuration is done.

Set "Personal" to define managed path for created web application. Steps are,
  • Select the created new web application under Manage Web Applications
  • Then, Click Managed Paths at top ribbon
  • Add "Personal" as New path and click OK




User Profile Config 

Do the following configuration steps,
  • Browse your Central Admin site
  • Click Manage service applications under Service Applications category
  • Create New User profile service if you do not have for it. 
  • Click New at top ribbon, then choose User Profile Service in drop down menu
  • Give a name for New User Profile Service Application and click Create
  • we may find created service application in Manage service application category
  • We will get the properties of Service once you clicked that
  • There we have option to click Setup Mysite under My Site Settings
  • Here, we will have lot of properties regarding my site. Give your My site host web application url in My Site Host option
  • Give permission to Everyone; All Users(Windows) in Read Permission Level option and click Ok at bottom
  • Then, Need to Review job definition in Monitoring --> Timer Jobs. Because, all feeds about users will get populate when this timer job is run at once



  • We will see the list of jobs. Select User Profile Service with Activity Feed job suffix (For ex: User Profile Service App - Activity Feed job) 

  • We may get Edit timer job properties once we clicked Review job definition
  • It shows 10 minutes by default. If you want change the time limit, do it. otherwise let it be and click Run Now

That' all. User Profile has configured in your SP farm

Sunday, August 3, 2014

Deploying WSP using Powershell Script

Introduction

I am to share the Powershell script which is use to deploy the wsp.

Script

Follow the below steps to create ps1 file

  • Open a notepad and paste this script

try
{
    Write-Host "Please make sure that ""SharePoint Administration"" and ""SharePoint Timer Service"" are running and then Press a key to proceed with installation.."
    $pressedKey = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    $currentLocation = Get-Location
    $solutionPath = "Give path of wsp with wsp file"

    #Step 1: Add WSP to solution store
    Write-Host "Adding solution to solution store.. " -ForegroundColor Yellow
    $spSolution = Add-SPSolution $solutionPath

    #Step 2: Deploying the solution to required web application
    #$webApplication = Read-Host "Please enter my site web application url to which solution needs to be deployed (Eg. http://<yourserver:port): "
    Write-Host "Deploying" $spsolution.Name ".." -ForegroundColor Yellow
    Install-SPSolution -Identity $spSolution.Name -GACDeployment

    #Step 3: Waiting for deployed status
    do
    {
        Start-Sleep -Seconds 1
        Write-Host "Waiting for Deployed status.."
    }while(-not($spSolution.Deployed))

   
    #Step 4: Completing installation
    
    Write-Host "wsp installation successful!!!" -ForegroundColor Green

}
catch
{
    Write-Host "Following is the error occurred while executing this script -->" $_
}


  • Then, save the text file with .ps1 extension
  • This is it, just run the powershell script file to deploy the wsp

Wednesday, July 16, 2014

Add ListView in SitePages using BinarySerializedWebPart

Introduction

I am going to share my idea about showing listview in sitepages using BinarySerializedWebPart. Let's see the steps for the same.

Save site as Site Template 

At first, Create a site and Create a list which you need to show in site page. Be sure about column names and view your going to show. For Example: If you want to show Name list in your site. Create a Name list in test site with same column. The steps are,
  • Create a list with needed columns (Ex: Name list)
  • Create any views for list if you want
  • Create one sitepage and insert this list webpart in the page
  • Then, Go to Site Settings --> Save site as Template
  • Give the File Name of template and click OK


  • We may get the success message if its done properly




Import Site Template

Go to Solution Gallery and download the template file in your local disk. Then, Import the wsp using Visual Studio. Steps are,

  • Create a SharePoint 2013 - Import Solution Package Project 
  • Choose Farm level  in Security level debugging window


  • Then, Browse the downloaded package and place it in Specify the new project source window and click Next
  • If you want to import particular items. then, select the items in Select item to import window. Otherwise Click Finish (All items has checked by default)
  • It will take sometimes to import the package. We may get the success message once its done. Then Click Ok

Paste BinarySerializedWebPart

Copy the BinarySerializedWebPart from imported solution and paste it on your SitePage's element.xml. Steps are,

  • Go to List Instance module in Solution Explorer, we may find SitePages list there
  • Then, We may get SitePages_1033_STS_doctemp_smartpgs when expanding SitePages list
  • Expand the SitePages_1033_STS_doctemp_smartpgs and open Element.xml



  • In Element.xml, we may find all sitepages with <File> tag.
  • Find the SitePage which is having listwebpart (Ex: I have put listview in test sitepage)
  • Copy the <view> tag of listview fully
  • Paste it in SitePages's Element.xml where you want show this listview
  • Change the WebPartZoneID and WebPartOrder as sitepage have.

  • That's all. Deploy your original solution in farm.  We may see the listview in sitepage where we pasted it.


Tuesday, July 15, 2014

Custom Masterpage reappears in Modal dialog

Introduction

 We might faced the master page problem which is applied to modal dialog also. I am going to share an idea to resolve this issue.

Solution

When we applying custom master page for our site. The master page will apply to modal dialog also.




To avoid this, we need to add s4-notdlg class in our all custom <div> / <table> in master page .

<div class="footer s4-notdlg">

Deploy your solution and check, this issue will get resolved.




Happy Coding .... !!!!!!




Monday, July 14, 2014

Get value of checked row in Listview Webpart

Introduction

I am going to share my idea about getting value of checked row in ListView webpart. I have achieved this using javascript.

Using javascript

After placed the webpart in sitepages. Just go to your sitepages in visual studio. Then add view button or label in that page to trigger the javascript. 

<input type="button" value="view" onclick="ViewCheckedElement()" />

Add the below script at bottom of sitepage or js file you already have.



function ViewCheckedElement() {
var r = $("tr.s4-itm-selected").attr("iid").split(",")[1];
alert(r);
}

This tr.s4-itm-selected class name will be added when we select the row in listview. We may find id of the row iid attribute.






Deploy the solution in your farm. That's all, an alert will come with checked items when you clicked the view button.