Wednesday, 29 January 2014

How to Hide Top Bar, Ribbon, Quick Launch in SharePoint 2010?

How to Hide Top Bar, Ribbon, Quick Launch in SharePoint 2010?

Top Bar, Ribbon, Quick Launch are come up with Application Pages by default. If you want to open the page in Dialog Framework then those elements will take more space and make the layout cluttered. You can remove these elements by creating new page layout which is cumbersome/time consuming.
One way to hide these controls is by passing a Parameter with the URL. [ ?IsDlg=1 ] SharePoint will hide these elements when It gets IsDlg Parameter on URL.
But every time we can't pass these parameters. Then how to get rid of these elements?
Simple Just add the below css Code in Application Page under PlaceHolderMain section.
<style type="text/css">
    #s4-ribbonrow, .ms-cui-topBar2, .s4-notdlg, .s4-pr s4-ribbonrowhidetitle, .s4-notdlg noindex, #ms-cui-ribbonTopBars, #s4-titlerow, #s4-pr s4-notdlg s4-titlerowhidetitle, #s4-leftpanel-content {display:none !important;}
    .s4-ca{margin-left:0px !important; margin-right:0px !important;}
</style>
This will hide the elements and only the content will be shown.
Note : If you use this code in SharePoint Site Pages with Content Editor Webpart then you can't check in the page since the toolbar goes hidden.
If you still want to use this code on Site Pages then add Content Editor Webpart and paste the above code. When you want to make other changes then open the page in browser with parameters [ ?Contents=1 ] which opens the page in WebPart maintenance mode. Remove the content editor webpart and re-open the page. Make the changes and add content editor webpart at last along the CSS Code. To check in the page use Site Pages Library.

How to use Notifications in SharePoint 2010?

How to use Notifications in SharePoint 2010?


In SharePoint 2010, Notifications is another way to display information/warnings without distracting user. It'll be shown in top right below Topbar and Ribbon. Just like Status bar, No Server side code or manual setup required to use Notifications. The required functions are bundled in SP.UI.Notify class that defined in SP.Js/SP.Debug.Js and it's included in SharePoint master page. So no manual include of Js is required.

Well, Status bar is used to display content and to hide developer has to invvoke RemoveStatus or RemoveStatusAll Method, whereas Notifications by default getting hide after few seconds. It's possible to make notifications Sticky(stay until closed by code).

SP.UI.Status Notify
The SP.UI.Notify class has 2 functions. They are
  1. SP.UI.Notify.addNotification(strHTMLContent, boolIsSticky) This function used to display specified content in Notification area. The parameters are self explanatory. boolIsSticky parameter specifies whether this content should be shown as sticky(true) or hide after few seconds(false). It's possible to show multiple Notifications at a time and they getting aligned themselves.
  2. SP.UI.Notify.removeNotification(strNotifyID) This function hides the Notification that passed as parameter.
Sample Code
<
Script type="text/javascript">
var
 strNotificationID, strStickyNotificationID;function showNofication()
{
  strNotificationID = SP.UI.Notify.addNotification(
"Quick Info : <font color='#AA0000'>Registration in Progress..</font> <img src='/_Layouts/Images/kpiprogressbar.gif' align='absmiddle'> ", false);
  strStickyNotificationID = SP.UI.Notify.addNotification(
"Sticky Notes : <font color='#AA0000'>Welcome to My World.</font> <img src='/_Layouts/Images/lg_ICPINNED.gif' align='absmiddle'> ", true);
}
function removeNofication()
{
  
if (strStickyNotificationID != null)
    SP.UI.Notify.removeNotification(strStickyNotificationID);
}
</Script>

<
div class="ms-toolpanefooter">
  <
input type="button" onclick="Javascript:showNofication();" value="Show Nofitication" class="UserButton" />
  
<input type="button" onclick="Javascript:removeNofication()" value="Remove Nofitication" class="UserButton" /> </div>
Notifications

How to set Favicon for SharePoint 2010 site?

How to set Favicon for SharePoint 2010 site?


What is Favicon?
Sometimes we come across some websites which shows their logo instead of explorer logo in Address bar. A typical example is Google, login to google with IE and watch address bar. You can see google logo then the URL. This icon is stored in the PC when we add the sites as bookmarks. When you open bookmarks menu the site name will show with the icon.
Favicon Preview

How to create Favicon?
It's very easy to create favicon. All you need is the company logo or image(in JPG/PNG/GIF format) which you want to create based on and internet connection. Open browser and enterhttp://tools.dynamicdrive.com/favicon/ . Then click Choose File Button and select your image. Click Create Icon Button. Now the site will create favicon based on image given and it's ready to download. Download and save it in your PC.

How to set Favicon to the SharePoint 2010 site?
SharePoint 2010 comes with a orange Favicon and it's present in SharePoint Root Folder\Template\Images [eg. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\]. Open this folder and search for favicon.ico and rename the file to FaviconBackup.ico. Now copy your favicon to this folder and make sure it's named as "favicon.ico". Now restart IIS(open Command Prompt -> IISReset), clear browser cache/temproary internet files. Close the browser and reopen then browse the SharePoint site.

If mulitple sites are hosted in same farm and need to set different favicons for different sites then we have to update Master Page Code. Open the site with SharePoint Designer 2010 and select Master pages -> v4.master. The default.master is still present in SharePoint 2010 for backward compatibility and visual upgrade. But SharePoint 2010 uses v4.master only. Now click "Edit File" link to add the favicon code. If it asks for check out, click yes and continue.

Find <SharePoint:SPShortcutIcon ID="SPShortcutIcon1" runat="server" IconUrl="/_layouts/images/favicon.ico"/> and change the path of favicon. Save and close (If you have checked out then you need to check in and site collection administrator has to approve it via Site Settings -> Galleries -> Master pages and page layouts -> Check in and Approve). Now reset IIS/clear browser cache and check.
To get this working for multiple browsers:
<SharePoint:SPShortcutIcon ID="SPShortcutIcon1" runat="server" IconUrl="/_layouts/images/favicon.ico"/>
...
..
Then, just above </head>, add the following:
<link rel="shortcut icon" type="image/x-icon" href="/_layouts/images/favicon.ico" />
<link rel="icon" type="image/ico" href="/_layouts/images/favicon.ico" />
<link rel="icon" type="image/png" href="/_layouts/images/favicon.png" > 

How to use ULS in SharePoint 2010 for Custom Code Exception Logging?

How to use ULS in SharePoint 2010 for Custom Code Exception Logging?


What is ULS in SharePoint 2010?
ULS stands for Unified Logging Service which captures and writes Exceptions/Logs in Log File(A Plain Text File with .log extension). SharePoint logs Each and every exceptions with ULS. SharePoint Administrators should know ULS and it's very useful when anything goes wrong. but when you ask any SharePoint 2007 Administrator to check log file then most of them will Kill you. Because read and understand the log file is not so easy. Imagine open a plain text file of 20 MB in NotePad and go thru line by line.

Now Microsoft developed a tool "ULS Viewer" to view those Log files in easily readable format. This tools also helps to filter events based on exception priority. You can read on this blog to know in details about ULS Viewer .

Where to get ULS Viewer?
ULS Viewer is developed by Microsoft and available to download for free. URL : http://code.msdn.microsoft.com/ULSViewer/Release/ProjectReleases.aspx?ReleaseId=3308
Note: Eventhought this tool developed by Microsoft, it's not supported by Microsoft. Means you can't support for this tool from Microsoft and use it on your own Risk. By the way what's the risk in viewing Log Files?!

How to use ULS in SharePoint 2010 Custom Code?
ULS can be extended to use in user solutions to log exceptions. In Detail, Developer can use ULS to log his own application errors and exceptions on SharePoint Log files. So now all in Single Place (That's why it's called "Unified Logging"). Well in this article I am going to use Waldek's Code (Reference Link). However the article is core and am writing container for that (Basically how to implement the code in Detail). Let's see the steps.
  1. Open Visual Studio 2010 -> File -> New Project -> Visual C# -> Windows -> Class Library -> Name : ULSLogger (Make sure you've selected .net Framework 3.5)
    Create Class Library Project


     
  2. In Solution Explorer Panel, Rename the Class1.cs to LoggingService.cs

     
  3. Right Click on References -> Add Reference -> Under .Net tab select "Microsoft.SharePoint"
    Add Microsoft.SharePoint Reference


     
  4. Right Click on the Project -> Properties. Select "Signing" Tab -> Check "Sign the Assembly".

     
  5. In the below drop down select <New> and enter "ULSLogger", uncheck the "Protect my key with a Password" option.
     
  6. Now copy the below code and paste. (Or Just refer.. :-) )

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using Microsoft.SharePoint.Administration;using System.Runtime.InteropServices;namespace ULSLogger
    {
    public class LoggingService : SPDiagnosticsServiceBase{public static string vsDiagnosticAreaName = "Venkats SharePoint Logging Service";public static string CategoryName = "vsProject";public static uint uintEventID = 700; // Event IDprivate static LoggingService _Current;public static LoggingService Current
    {
     get  {   if (_Current == null)
        {
          _Current = 
    new LoggingService();
        }
       return _Current;
      }
    }
    private LoggingService()
    : 
    base("Venkats SharePoint Logging Service", SPFarm.Local)
    {}
    protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
    {
    List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>
     {
      new SPDiagnosticsArea(vsDiagnosticAreaName, new List<SPDiagnosticsCategory>
       {
        new SPDiagnosticsCategory(CategoryName, TraceSeverity.Medium, EventSeverity.Error)
       })
      };
    return areas;
    }
    public static string LogErrorInULS(string errorMessage)
    {
    string strExecutionResult = "Message Not Logged in ULS. ";try
     
    {  SPDiagnosticsCategory category = LoggingService.Current.Areas[vsDiagnosticAreaName].Categories[CategoryName];  LoggingService.Current.WriteTrace(uintEventID, category, TraceSeverity.Unexpected, errorMessage);
      strExecutionResult = 
    "Message Logged";
    }
    catch (Exception ex)
    {
     strExecutionResult += ex.Message;
    }
    return strExecutionResult;
    }
    public static string LogErrorInULS(string errorMessage, TraceSeverity tsSeverity)
    {
    string strExecutionResult = "Message Not Logged in ULS. ";try {
     
    SPDiagnosticsCategory category = LoggingService.Current.Areas[vsDiagnosticAreaName].Categories[CategoryName]; LoggingService.Current.WriteTrace(uintEventID, category, tsSeverity, errorMessage);
     strExecutionResult = 
    "Message Logged";
     }
    catch (Exception ex)
     {
      strExecutionResult += ex.Message;
      }
    return strExecutionResult;
     }
    }
    }

     
  7. Just build the solution and it's ready to use now.
This ULS solution can be used in SharePoint Webparts or Console Application. Lets see how to use it in a Console Application.
SharePoint Server 2010 must be installed in the same Server or the application must be hosted in SharPoint Server 2010 environment. The console application must be set to "x64" Platform target.
  1. Create a New Console Application. (Visual Studio -> File -> New Project -> C# -> Windows -> Console Application)
  2. Right Click on References -> Add Reference -> Under .Net tab select "Microsoft.SharePoint"
  3. Open Program.cs add "using Microsoft.SharePoint.Administration;"
  4. Right Click on References -> Add Reference -> Under "Browse" tab select the "ULSLogger.dll" which we created first. (Path : ULSLogger\ULSLogger\bin\Debug\)
  5. Right Click on Project -> Properties -> Select "Build" Tab -> Under "Platform Target" option select "x64".
  6. Open the Program.cs and paste the below code.

    using System;using System.Collections.Generic;using System.Linq;using System.Text;
    using Microsoft.SharePoint.Administration;using ULSLogger;

    namespace ULSLoggerClient
    {

      class Program  {
       static void Main(string[] args)
        {

         Console.WriteLine("ULS Logging Started.");

         string strResult = LoggingService.LogErrorInULS("My Application is Working Fine.");     Console.WriteLine("ULS Logging Info. Result : " + strResult);

         string strResult = LoggingService.LogErrorInULS("My Application got an Exception.", TraceSeverity.High);
         Console.WriteLine("ULS Logging Waring Result : " + strResult);     Console.WriteLine("ULS Logging Completed.");     Console.ReadLine();
        }
      }
    }


     
  7. Just build the solution and execute. It'll log the message on the log file. Make sure you are using Farm Administrator User ID.
    ULS Logging Console Application


     
You can play with Message and TraceSeverity as required.
Now Open ULS Viewer(Read Second section of this article to get ULS Viewer) -> File -> Open From -> ULS -> Select First Option to open the default ULS Log.
Select ULS Log File


It's Uls RealTime and will show all log entries in readable table format. Right Click on a row and select "Filter By This Item". Select "Event ID" and enter value "700" that we used in the application.
ULS Log Viewer - Log Filter


Click Ok and now you'll see the Exceptions/Logs which logged by our application. SharePoint by default log each and every exceptions on ULS so it'll take couple of minutes to list all Exceptions. See the Status bar on ULS Viewer. If it's "uls Running" then it's still reading the Logs to display. Provide your Filters and wait for few minutes.
ULS Log Viewer


If you want to see High Priority Messages only then Click Icons except Red Cross Icon on the Toolbar. The tooltip will tell what's the icons used for. 

Document Sets in SharePoint 2010

Document Sets in SharePoint 2010:-

Document Set is a new feature introduced in SharePoint 2010 as part of content/document management. Document set helps to manage group of documents as a single entity. Actualy Document set is a content type that can be attached to any document library and make use of it's features.

Advantages of Document Sets
Consider a type "Project", each project has requirements document, project effort estimation spreadsheet, project plan presentation. To standardize the project management process, it's enforced to have all these documents for every project. In SharePoint 2007 it's not so easy to group different documents in same document library as each document is individual item. But this can be done within few minutes with Document sets feature. Documents sets will have Templates for each document, ie a predefined format document for review document, effort estimation, project plan presentation can be attached while defining this document set content type. Each library which uses this content type will get those document templates when user creates new document set.

Apart from these document sets can be versioned. It can have it's own customized Welcome page which is like home page for the project. Document Set content type basically inhertited from "Document" content type. Other content types also can be added if required. Workflows can be attached and few more options provided in SharePoint designer for document sets.

 


How to enable Document Sets?
Document sets by default won't be enabled in SharePoint 2010. It's a feature and has to be enabled manualy. Then document sets Content type has to be customized (if required). After that it can be attached to Document libraries. First keep all project document templates (Requirements document, Effort Estimation, Project Plan Presentation) ready.
 
  1. Login to SharePoint 2010 site -> Site settings -> Site Administration -> Site Collection Features -> Document Sets -> Activate.

 
  1. Site Settings -> Galleries -> Site Content types -> Document Set Content Types -> Document Set.

 

  1. Select Document Set Settings.

 
  1. Under Default Content section select the templates. Click "Add new default content" to select and upload more template documents.

 
  1. Now we'll create new document library. If you want to attach to existing document library then skip this step.

 
  1. Open the document library -> Library (Tab) -> Library Settings.

 
  1. Under General Settings select Advanced Settings. We need to enable allow management of content types setting.

 
  1. Under Content types Select Yes for "Allow management of content types?" and save/Click Ok.


 
  1. Now in the library settings page Content types section will be shown. Select "Add from existing site content types".


 
  1. Under "Select Content types" section select "Document Set" and Add. Now click Ok.


 
  1. In library settings -> Content types section -> Document sets -> Settings -> Name and description. Change name as "Project Plan".


 
  1. Open the document library -> Documents (Tab) -> New Document -> Project Plan.


 
  1. Provide a project name for eg. "Aqua" -> Ok.


 
  1. Now a Project Plan Document set created with all default template documents. You'll be landed in Project Plan Welcome Page. :)


 
To change Welcome page and other settings, check Document Sets Content type settings.

Note: Document sets is feature of Microsoft SharePoint Server 2010 (MSS 2010) and won't be available on SharePoint Foundation 2010.


How to do enable Target Audience in SharePoint 2010?

How to do enable Target Audience in SharePoint 2010?


I've installed SharePoint 2010 and create first site collection. When I try to specify Target Audience for Announcements webpart in Home page via WebPart Properties, there is no "Target Audience" option. When I did google, articles which specifies how to set Target Audience for List. But that's not what I need. This article will explain how to get Target Audience for webpart in SharePoint 2010 sites.

How to specifiy Target Audience for Webpart in SharePoint 2010?
Well, It's obvious that free versions WSS 3.0/SharePoint Foundation 2010 won't provide Target Audience feature. SharePoint 2007/SharePoint Server 2010 is required for the same. I have MSS 2010 and still not getting Target Audience option for webparts, what to do? A service which determines Target Audience should be enabled and running. It's SharePoint User Profile Service that depends on "User Profile Synchronization Service". So first check the Services via Central Administration -> System Settings -> Manage Services on server.

Check the status of "User Profile Service" and "User Profile Synchronization Service" (This service required to compile audiences. If you have fixed no of users and don't want scheduled syncrhonization then later you can disable it). Check the SharePoint Server Search Service status. It must be started, if so then Start the above 2 specified services(UPS and UPSS).

Now we need to configure audiences in User Profile service application. Open Central Administration -> Application Management -> Manage Service Applications. Check status of "User Profile Service Application" and it should be "Started" (otherwise go to previous step and run User Profile Service). Now Click "User Profile Service Application" link. It'll open the user profile service application settings.

Select Configure Syncrhronization Connections and create new connection if required.
Configure Synchronization Connections
Create New Connection


Provide LDAP Connection details and click "Populate Containers" button to list all domain containers. Select "Domain -> Users" (or whichever container that has user details) Note: It'll take few minutes based on network traffic. Then click "Ok" to create the connection.

New Connection Settings


User Profile Synchronization service must be started otherwise it'll show error.
Error


If you've created new connection then open "Configure Synchronization Timer Job" and run it now.

How to create Target Audience in SharePoint 2010?
Central Adminstrion -> Application Management -> User Profile Service Application -> People -> Manage Audiences.

Manage Audiences

It'll show audiences if created already. Otherwise click New Audience -> specify name, description, owner.
Create Targer Audience


Select a option based on requirement (I chose "Satisfy any of the Rules"). Click Ok to go next page. Select Properties and select the property. Specify the value to compare. Now it'll show the Audience properties. Click "Compile Audience" link to validate AD Users and add if the details satisfy specified condition.

Create Targer Audience


Login to your SharePoint site and edit any webpart. It'll now show the option to specify Target Audience.

Thursday, 7 March 2013

PowerShell Error : Able to run SharePoint command lets directly on powershell window, but not able to execute PS1 file

PowerShell Error : Able to run SharePoint command lets directly on powershell window, but not able to execute PS1 file, which iterate thru the site and list all available collections. This happened in SharePoint VM, where SharePoint installation happened with different admin account and later user account is added as Farm administrator.




Solution:
    After an few hours of analysis, it has been sorted out by doing changes in SQL Server by enabling "DBOwner"access for users account for the SharePoint database's named "WSS_content" and "WSS_Search" and "SharePoint_Shell_Access" for "SharePoint_config" database.