Monday, July 22, 2013

Web part- lists sites based on Site template like blog community

Web part to display all community sites in a site collection, with details,

http://en.share-gate.com/blog/sharepoint-2013-content-search-site-portal

If you took a peek at SharePoint 2013 recently, you may have noticed there is a new Site Collection called the Community Site Portal. This new site works in conjunction with the Community Site template. In short, it’s a site that shows you a list of all Community Sites. My goal is to do the same thing but for other types of Sites, for example a Team Site portal.
SharePoint 2013 Content Search Site Portal
 

Reverse engineering

Best way to understand how SharePoint works is sometimes to dig in to what is presented in front of us. Something quickly jumped at me when I looked at the Community Site Portal, there is a “number of results” shown at the bottom of the page and changes made to the Community Site do not appear immediately. My first thought is that it must be based on the new SharePoint 2013 Search engine. As I mentioned in a previous article, we can leverage the power of search now with the Content Search Web Part or the Search Results to build our sites.
Let’s begin by editing the page and see how this has been built:
SharePoint 2013 Content Search Site Portal


As you can see, the portal is nothing more than the result of a Search Query. It looks like the Content Search Web Part was added with a pre-configured Search Criteria and a custom Display Template. All we need to do now is take a look at the default Query and adapt it to our needs.

The default Content Search Criteria for the Portal

Essentially there is no manual search here; the Web Part is configured with a Search Criteria or a query if you want to display the Community Sites below. We can try to understand it a little better by clicking on the Change Query button in the Web Part properties.
SharePoint 2013 Content Search Site Portal


Then we will have the new SharePoint 2013 Query Builder that is used in many Search Web Parts and settings. Within the Query Builder, we can see right away how it is able to get all the Community Sites for the Portal. And frankly, I am surprised at how easy it is to get it.
SharePoint 2013 Content Search Site Portal
The Query simply says to grab “WebTemplate:Community”; in other words go get all the Sites that are built with the WebTemplate called Community.

Making a SharePoint 2013 Team Site Portal

My first objective is to change the query for the Web Part to something that will get only Team Sites instead of Community Sites. What I did is created a new Site Collection to do my tests based on the Team Site Template. I then Activated the Publishing Infrastructure Site Collection Feature. Finally I created a blank Wiki page in Site Pages and added the Content Search Web Part on it.
SharePoint 2013 Content Search Site Portal


I jumped to the Query Builder of my new Content Search Web Part and doing something I covered recently in “Rolling up SharePoint Sites with Content Search” I erased the Query Text box with whatever query was there by default. Then in the Keyword Filter dropdown menu, I selected the “Return Only Sites” option.
SharePoint 2013 Content Search Site Portal
Why am I selecting this Keyword Filter?
That’s an excellent question, technically I could just modify the “WebTemplate:Community” by one that represents the Team Site WebTemplate.
In this scenario, I am assuming that we do not know what the WebTemplate names are.
By selecting this Keyword Filter and only returning sites, we can jump to the “Refiners” tab in the Query Builder at the top and let SharePoint do the work for us.
SharePoint 2013 Content Search Site Portal
Awesome! Now I know how to write the value for my Query Text. Instead of using “WebTemplate:Community” I can try “WebTemplate:STS” for Team Sites for example.
Let’s go back to the Query Text box and type in our new value:
SharePoint 2013 Content Search Site Portal
Let’s try it out, click on Ok and Save or Apply your changes to see your page again.
SharePoint 2013 Content Search Site Portal


Now you can build your own SharePoint 2013 Site Portal based on any Site Template you want to. You could even push this even further by customizing the Query with other Site Properties. The issue is always in finding what these properties are.
Let’s see if it works with our Blogs as well:
WebTemplate:BLOG
SharePoint 2013 Content Search Site Portal
I am really happy to see how easy it to change the Content Search, even as a Power User I can see this being very helpful to many.


Making it look like the Community Portal – Using the Display Templates

So we managed to build our own SharePoint 2013 Site Portal for Team Sites or even Blogs. But something is missing, the look and feel of the Portal. In my previous post on the Content Search, I already talked about Display Templates and how to change the property mapping to put the values of the properties we want in our favorite Display Template.
Unfortunately, none of the default Content Search Display Templates matches the look and feel we got from the Community Portal. So I am going to cheat and do something I learned with the Content Query Web Part back in SharePoint 2007 and SharePoint 2010. The trick is to export the Web Part found on the Community Portal on to your Desktop and Edit it with Notepad. I noticed that it gets it’s Display Template for items in a System folder of the Site Collection Catalog.
~sitecollection/_catalogs/masterpage/Display Templates/System/Item_CommunityPortal.js
I have a few options; I can export my Content Search Web Part and add the same links for the same properties as the ones in the Community Portal. I can Copy Paste the Display Template from the System folder to Content Web Parts in the Display Templates folder. Obviously I do not recommend the ladder but I do understand that sometimes we just do not have the luxury. You can also go directly to the Display Template stored in the System folder of the Display Templates and change the hidden value from 1 to 0. You will then be able to use it in your Content Search.
SharePoint 2013 Content Search Site Portal

Friday, July 19, 2013

Create site and apply theme programmatically- SharePoint 2013

 Below code will create  a community site with new master page and theme

try
            {
                SPSite site = SPContext.Current.Site;
                             try
                             {
                                 SPWeb newWeb = site.AllWebs.Add(txtTitle.Text, txtTitle.Text, txtDescription.Text, 1033, "COMMUNITY#0", true, false);
                                 newWeb.AllowUnsafeUpdates = true;
                                 newWeb.Update();
                                 newWeb.MasterUrl = "/_catalogs/masterpage/NewMaster.master";
                                 newWeb.AllProperties["__InheritsThemedCssFolderUrl"] = "True";
                                 newWeb.Update();
                                 SPFile file = site.RootWeb.GetFile("/_catalogs/theme/15/Palette012.spcolor");
                                 SPTheme s = SPTheme.Open("S", file);
                                 s.ApplyTo(newWeb, true);
                                 newWeb.AllowUnsafeUpdates = false;
                                 SPUtility.Redirect(site.Url + "/" + txtTitle.Text, SPRedirectFlags.Trusted, Context);
                             }
                             catch (Exception es) { }
                                finally {}
            }

Wednesday, July 3, 2013

Add an item into SharePoint List using Javascript

Below code is used to add list item into the SharePoint list using Javascript,



var FeedbackClientContext;
var FeedbackWebsite;
var FeedbackCurrentUser;
var FeedbackList;
 

function AddFeedbackValue()
{
var FeedbackNoteValue= $.trim($("#txtFeedback").val()); // txtFeedback name of the text box html field
if(FeedbackNoteValue.length > 0)
{
FeedbackClientContext = new SP.ClientContext("/");
   FeedbackWebsite = FeedbackClientContext.get_web();
FeedbackList = FeedbackWebsite.get_lists().getByTitle('Feedback'); // name of the SharePoint list
var FeedbackListItemCreInfo = new SP.ListItemCreationInformation();
   var FeedbackNewItem = FeedbackList.addItem(FeedbackListItemCreInfo);
   FeedbackNewItem.set_item('Feedback',FeedbackNoteValue);
   FeedbackNewItem.update();

   FeedbackClientContext.executeQueryAsync(Function.createDelegate(this, this.onFeedbackQuerySucceeded),
    Function.createDelegate(this, this.onFeedbackQueryFailed));
    }      
}

function onFeedbackQuerySucceeded(sender, args) {
$("#txtFeedback").val('');
}

function onFeedbackQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


Thanks,
-Sendil

JavaScript to get user details from UserProfileProperties



to get more properties 


Thanks,
-Sendil

Lync Presence in SharePoint - webpart

Sharepoint web part to display the presence(Lync) of an user using Javascript 

is

User Presence 

where as

personProperties.get_email() in

IMNRC(\""+personProperties.get_email()+"\")
is email address of an user which is basically fetched from UserProfile property of current user in Javascript
else if we want to hard code, processed as below

IMNRC("aaa@example.com")

Thanks,
-Sendil

Sunday, January 31, 2010

Creating a Scope and Tab for MOSS Search Center

Creating a Scope and Tab for MOSS Search Center
I am occasionally asked how to create a tab in the MOSS Search Center to search a given scope. This process is often confusing to administrators because it involves the creation of a scope, making the scope available, and then the creation of not just one, but two tabs in Search Center along with ASPX pages. Before beginning, this article assumes that you already have the Shared Services Provider (SSP) properly set up and that you have a "Search Center with Tabs" site available in your portal. For my example, I'll create a tab designed to search a specific document library that contains HR documents. Note that this article does not cover creating an "Advanced Search" capability - just a simple keyword search.
Create the Shared Scope
The first step is to create a Shared Scope that will target the document library. This Shared Scope will be set up in the Shared Services Provider using the following steps:
On the home page of the Shared Services Administration site, click "Search Settings"
On the Search Settings page, click "View Scopes"
On the View Scopes page, click the "New" button
On the Create Scope page- Enter HR Documents in the Title field- Leave the results page using the default page, you'll change that later- Click the OK button.
On the View Scopes page, locate the new scope and click the "Add Rules" link
On the Add Scope Rule page- Set the Scope Rule Type to "Web Address"- Set the Web Address to "Folder"- Enter the complete URL to the Document Library (e. g. , http://litwareinc.com/HR/HR%20Documents).- Click the OK button.
Return to the Search Settings page
Under the Scopes section, click the "Start Updates Now" link
When you have completed creating the scope and updating it, you should be able to see that it contains a number of documents. This is a good check that you have created the scope correctly and it contains the number of documents that you expect.
Make the Shared Scope Available in the Site Collection
An optional step is to make the new scope available to the site collection where the Search Center is located. Follow these steps to do that:
From the home page of your portal, select Site Actions>>Site Settings>>Modify All Site Settings
On the Site Settings page, under the Site Collection Administration page, click the "Search Scopes" link
On the View Scopes page, you should see the new scope listed under the Unused Scopes section. At this point, you could easily add the scope to the Search Dropdown that appears at the top of the page in MOSS by clicking on the "Search Dropdown" link appearing in the "Display Group: Search Dropdown" section. However, our goal is to create a tab for the search scope.
Create the Search Center Tab
New tabs for Search Center involve several different parts. First, you must create a search page. Then you must create a search results page. Finally, you must associate the scope with the new pages and create tabs to display them. Follow these steps to get it all working:
From the Search Center page, select Site Actions>>Create Page
On the Create Page- Enter HR Documents Search in the Title field- SharePoint should automatically generate a valid page name- Select "Search Page" from the list of available Page Layouts- Click the Create button
A new page should now be visible with a Search Box web part- Select Modify Shared Web Part from the web part's edit menu- Expand the Miscellaneous section- Enter HRDocumentsResults.aspx in the Target Search Results Page URL field (you will create this page next)- Uncheck the box labeled "Display Advanced Search Link"- Click the OK button- Click the Publish button at the top of the page
From the new page, select Site Actions>>Create Page
On the Create Page- Enter HR Documents Search Results in the Title field- SharePoint should automatically generate a valid page name- Select "Search Results Page" from the list of available Page Layouts- Click the Create button
A new page should now be visible with a several search web parts- Select Modify Shared Web Part from the Search web part's edit menu- Expand the Miscellaneous section- Enter HRDocumentsResults.aspx in the Target Search Results Page URL field- Uncheck the box labeled "Display Advanced Search Link"- Click the OK button- Select Modify Shared Web Part from the Search Core Results web part- Expand the Miscellaneous section- Enter HR Documents in the Scope field- Click the OK button- Click the Publish button at the top of the page
From the new page, select Site Actions>>View All Site Content
On the All Site Content page, click the "Tabs in Search Pages" link
On the Tabs in Search Pages list, click the New button
On the New Item page- Enter HR Documents in the Tab Name field- Enter HRDocumentsSearch.aspx in the Page field- Click the OK button
From the list, select Site Actions>>View All Site Content
On the All Site Content page, click the "Tabs in Search Results" link
On the Tabs in Search Results list, click the New button
On the New Item page- Enter HR Documents in the Tab Name field- Enter HRDocumentsSearchResults.aspx in the Page field- Click the OK button
Return to the Search Center home page and you should now see a new tab visible for HR Documents.
Try out a search and verify the expected results.
http://scothillier.spaces.live.com/blog/cns!8F5DEA8AEA9E6FBB!734.entry