Wednesday, August 27, 2014

Site Pages library is missing in SharePoint site

We may face "SitePages list doesn't exist" issue while activating feature. To resolve this problem, We need to activate "Wiki Page Home Page" feature.


Tuesday, August 26, 2014

Showing Image Popup while clicking images in NewsFeed Webpart

Introduction

I already given some ideas about Newsfeed webpart. Now, I am going to give an idea to show image popup when we click an image in NewsFeed.


Customization

Here too we can do the customization newsfeed webpart in both Direct and Programmatic way. 

Direct

After placing Newsfeed webpart in sitepage, Then, Upload a jquery library in Site Assets. Download the plugins here Add a Script Editor webpart in same page. Edit the Script Editor and paste below script.

<script type="text/javascript" src="/SiteAssets/jquery.min.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.popupoverlay.js"></script>

<script type="text/javascript">

$('.ms-microfeed-attachmentImage').addClass('feedPopup_open'); //adding class to image
 $('#feedPopup').popup(); 
//On click method for an image

 $('.ms-microfeed-attachmentImage').click(function () {

        var image_href = $(this).attr("src"); //getting image source
        $('#divFeedDescPopup').html('<img src="' + image_href + '" />'); //appending an image with popupblock
    });

</script>


<!-- Style for popup -->

<style>
.popupContent p label {
    display: block;
    font-weight: bold;

}
.popupContent img {
    width:100%;

}
</style>

<!-- Popup block -->
<div id="feedPopup" class="popupBlock" style="width: 30%; display: none">
<div id="divFeedDescPopup" class="popupContent"> </div>
 <button class="feedPopup_close popupClose">Close</button>
</div>


That's all save the page. Popup will display for each images in newsfeed webpart.

Programmatically

Add a sitepage in your solution within module. And paste the jquery library files in _layout folder. Then, Refer those library files in sitepage. Paste the above script, style and popup block in the page. Deploy the solution and see the popup while clicking an image in Newsfeed.


Setting Row Limit in CAML Query

Here, I am going to give an example to set RowLimit for list items in CAML Query.

Query

<View>
<Query>
<OrderBy>
                                    <FieldRef Name="Created" Ascending='FALSE'/>
</OrderBy>
</Query>
<ViewFields>
<FieldRef Name="ID"/>
<FieldRef Name="Title"/>
<FieldRef Name="Job_x0020_Title"/>
<FieldRef Name="Email_x0020_ID"/>
<FieldRef Name="Member_x0020_Name"/>
</ViewFields>
<RowLimit Paged="TRUE">1</RowLimit>

</View>

Sunday, August 17, 2014

Applying ellipsis in NewsFeed Content

Introduction

As all we know we have NewsFeed webpart to display our activities in Mysite. The NewsFeed contents are not applied with ellipsis style. So, the content height will get enlarge automatically. Here, i am going to share an idea to apply ellipsis for content.

NewsFeed Webpart

First, We need to place the newsfeed webpart in our page. The method is our choice whether it may be applied directly or programmatically. If you need to go with programmatically, Click here

Cutomization

Customization will differ based on way we chose to place the webpart directly / programmatically in the page. Let we see both customization here.

Directly

First place the Newsfeed webpart in sitepage. Then, upload the jquery library in Site Assets. 
Add ScriptEditor in the page. Open the ScriptEditor and place the below script.

<script type='text/javascript' src="/SiteAssets/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function ($) {
$('.ms-microfeed-replyText span').addClass('replyEllipsis');

 $(.ms-microfeed-replyText span').click(function () {
        if ($(this).hasClass('replyEllipsis')) {
            $(this).removeClass('replyEllipsis')
        }
        else {
            $(this).addClass('replyEllipsis')
        }

    });
});
</script>

CSS for replyEllipsis

<style> .replyEllipsis {
    width:250px;
    overflow: hidden;
    -ms-text-overflow: ellipsis;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
</style>

Here, I did code for ellipsis for reply text in Newsfeed. I have found <div> tag of reply container, they form <span> for reply text. I am getting <span> and added new class in it. Already made css for that class (replyEllipsis). The jquery has added the class in <span> tag at page load. And i did toggle type of code to apply ellipsis for reply text (ON/OFF).

Programmatically

Add the <script> in the sitepage and paste the above script. Deploy the solution. The Ellipsis will apply in Newsfeed webpart.

Wednesday, August 13, 2014

Changing list view properties in Listview webpart Programmatically

Introduction

As well know about views in Lists and Listview webpart which is used in sitepages/pages. Here i am going to share an idea about changing views of listview webpart programmatically.

ListView Webpart

We can use listview webpart to display and edit list items in Sitepage/Page. It displays information in different ways for different purpose such as filtering, sorting / selecting specific columns. Its a short note about listview webpart. Now, Let's see how to add list view webpart programmatically.

Adding Listview Webpart


Changing properties of view in Listview Webpart

We are going to access the webparts in a page using SPLimitedWebPartManager. Then, Get the webpart by using condition check with webpart title. Convert the webpart as XsltListViewWebPart. Take view from it and change as we want. For instance, I have changed the number of rows in listview. 


  web.AllowUnsafeUpdates = true;

        XsltListViewWebPart webPart = null;
        SPLimitedWebPartManager wpManager = SPContext.Current.Web.GetLimitedWebPartManager("your page name", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpManager.WebParts)
        {
          if (wp.Title.Equals("Webpart title"))
                    {
webpart = wp as XsltListViewWebPart;
var currentView = webPart.View;
                currentView.RowLimit = Convert.ToUInt32(3);
                currentView.Update();
                web.AllowUnsafeUpdates = false;

}
}

This is code to change row limit. we may change some of the properties in View. That's it.

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