Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Tuesday, September 24, 2013

Content Query web part --Querying multiple specific lists

Hi guys,

How to query the data from multiple lists in SharePoint using content query webpart?

 I have a simple requirement to display the latest 5 document links from multiple document libraries in the current site.

 In general, share point out of the box feature provides the way to query the data from a particular list or all the lists/document libraries in a site or entire site collection.

 If you want to query the data from multiple specific lists, you have to do in in the below way.

 Add the content query webpart to the page,by editing the page and it comes in Content Roll up category. Note- if you are not able to see content query webpart in content roll up category, then your site's publishing feature is not activated. Activate that feature at the site collection level and also at the site level [make sure you have site collection administrator rights.]

 In the content query web part tool box section, select the radio button, that shows "select all the lists/document libraries in the site" and do the remaining filter and sort options, presentation things as per your requirement.

 Finally click Apply button ,then save the page and do the export web part.

 Open the .webpart file after you export it, modify the .webpart file in designer and then find the below property "ListsOverride ".

Get the List GUIDs from the list settings page, for which you want to query the lists.

 Modify that tag similar to the below one.









Saturday, April 20, 2013

Modify Webpart Title Color, background color, Header background,

Hi All, Recently I had to work on some custom css changes in my team site home page. I need to change the Color of the Webpart titles, background color of the total webpart and header. To achieve these things easily ,I first had to go to developer tools (short cut : F12 or Tools -->Internet options -->Developer Tools) of the required page and then understood what the css classes were written in CoreV4.css file for existing styles of the web part and the page. We need to override these css classes in our custome code in master page or CEWP. Here is my work for different categories.

Code for changing the color of Webpart title

 <style type="text/css">
  
 .ms-WPTitle {
  
      COLOR: #d47600; FONT-WEIGHT: bold
  
 }
  
 .ms-WPTitle A:link {
  
      COLOR: #d47600; FONT-WEIGHT: bold
  
 }
  
 .ms-WPTitle A:visited {
  
      COLOR: #d47600; FONT-WEIGHT: bold
  
 }
  
 }
  
Code for Changing webpart header background color
 <style type="text/css">
  
 .ms-WPHeader {

BACKGROUND-COLOR:Trasperant;

}
}
Code for Changing the Total Webpart background color: If you want to change the background color for a required webparts in the page, you should first locate the id of the webpart. This could be found by using again developer tools, open developer tools, select "Find Element by click" on menu, switch to your site page, then locate the webpart with mouse and then identify ID highlighted in Developer tools. Here is the script for that changing color:
 <style type="text/css">
  
 .s4-wpcell#MSOZoneCell_WebPartWPQ7 {

BACKGROUND-COLOR:blue
}
}
In the above snippet,.s4-wpcell is the css class for total webpart box and we are applying only for the webpart with the id "MSOZoneCell_WebPartWPQ7 ". if you want to change for all the webparts, you could directly use the single css code like here
 <style type="text/css">
  
 .s4-wpcell{

BACKGROUND-COLOR:blue
}
}
Code for removing the headers of list/document libraries
 <style type="text/css">
  
 .ms-viewheadertr{

 Display:none;
}
}  
Code for removing left quick launch panel
 <style type="text/css">
  
 #s4-leftpanel{

 Display:none;

}
}  
You can apply directly in CEWP for quick testing of these css snippets.
For adding the styles in master page, it would be recommended to maintain a separate style sheet in styles library of the top level site and give that style sheet reference in master page head tag like below.
 <link rel="stylesheet" type="text/css" href="../../style%20library/CustomCSS/Mystyles.css" />   

Add Background image to the site page

Hi Guys, I had a requirement from customer to add a background image to the existing site page. I just wrote a css style to achieve this through Content editor webpart. Here I noted downn my brief work . The Background image needs to be applied to the BODY tag of the page and here is my css script.
 <style type="text/css">
  
 BODY{
  
 background-image:url("/sites/yoursite/images/bgimage.jpg");
  
 background-position:center;
  
 background-repeat:no-repeat;
  
 }

.s4-ca {
 BACKGROUND-COLOR: transparent
}

  
In addition to the above code,you must add the background color transperent style to overcome the white background. Use this code in CEWP, if you have a requirement in only page, Otherwise, add the same style snippet in Master page head tag if you have enough permissions.

Sunday, January 20, 2013

SharePoint Content DB size mismatch

Hi, Once you enable the quota limit in central admin for a site collection and do check the _layouts/storman.aspx page, you are able to see the site storage space. But, you may find some difference in the actual content db size and the statistics shown in the above page. To recalculate it again, use the below power shell script. $site=get-spsite -identity http://sitecollectionurl $site.RecalculateStorageUsed()

Saturday, January 19, 2013

Back up the farm using power shell

I got a requirement from my client to take the backup of the farm on a weekly basis using automated scheduler.

we do have a standard powershell cmdlet, that helps us in taking the back up of farm using backup-spfarm cmdlet.

We could do the job on a dialy or weekly basis with power shell script and windows task scheduler.

After I searched for some time , I got an excellent blog from http://sharepointpolice.com/ .

Here is the same script , I used for my farm.

Hide fields in the list view web part using jquery

Hi Guys,

I had a requirement to hide the list fields in the list view web part.

For example, in a workflow, I have a course training custom list with multiple columns, where the students want to enter their data like name, course required, timings etc and course  faculty need to see additional fields like approved/rejected, his availability etc.

For students, they should not see approved column while they submit the course request.

This could be possible through  a simple j query, in a content editor web part with specifying target audience.

Here is the jquery code.

$('nobr:contains("Approved")').closest('tr').hide(); //"Approved" is your required column to hide.

The code works like this
When you go to view source of the page, you could see the fields names with the tag "nobr" associated to it. So query those tags with jquery selector and hide its nearest 'tr'.

So if the above code does not work for you, make sure  to check the view source of the page and see the field name tags.


Thursday, November 1, 2012

SharePoint 2010 Birthday webpart

Hi ,

I had a small requirement from my manager to display the team mates birth days in the team site for the current month.

I searched for the  already existing solutions in the net and able to replicate one of them using a simple OOB approach.

You just need a custom list to store the team mates names and birth day dates and need to do some calculated columns . Thats enough.

Below are the steps explained.

  1. Create a custom list named TeamBirthdayList and add the columns name, birthday as date type and other details if needed to display like mail id and mobile no.
  2. create a column named "currentdate" and make default value as today's date with date only.
  3. Create two calculated columns named "startmonth" and "endmonth".
  4. startmonth calulated formula as DATE(YEAR(currentdate),MONTH(Birthday),1)
  5. endmonth calulated formula as DATE(YEAR(currentdate),MONTH(Birthday)+1,1)-1.
  6. Now create another column named "BirthdayOrder" as calculated column to sort the list according to the date. the formula will be like this : DATE(YEAR(currentdate),MONTH(birthday),DAY(birthday))
  7. Now, add this list as listview webpart in the page and change the view settings like below steps. 
  8. Sort the items as per birthday order field .
  9. IN the filter section, startmonth is less than or equal to [Today] and endmonth is greater than or equal to [Today]
Thats it. your teams birthday webpart is ready and you can customize the styles using xslt.

Sunday, October 14, 2012

Powershell startup

Hi Guys,

I started learning powershell scriping recently and I noted my learning updates here for quick reference

  1.  To add powershell snap-in
           Add-PSSnapin Microsoft.Sharepoint.Powershell

If you are unable to add snapin to the powershell console, you may not have sufficient permissions to do the scripting.

Here are the steps to get the permissions to run the scripts.

You should have access to sharepoint shell configuration database and here is the cmdlet.

Add-SPShellAdmin -username contoso\user1

You have to perform the above step by using farm administrator privileges. The above command adds the user name specified to the Sharepoint_shell_access role on the configuration database.

If you want to give permission to a specific content database for a webapplication, specify the database parameter
Add-SPShellAdmin -username contoso\user1 -database guid



   2.    To get help on any command,
           help Get-SPSite

    3.   To get examples on the cmdlet.

          Get-SPSite -examples

4.        To get information about the site,

          Get-SPSite http://litware | select owner, Name, Description

5.       To know about the features in a site collection

         Get-SPFeature -site http://litware
6.      To activate the features

         Enable-SPFeature -identity GUID -url http://litware

7.    To install the feature,

        Install-SPFeature featurename
        e.g Install-SPFeature  MyCustomFeature
       Before installing the feature, make sure that, the feature files are deployed correctly in 14 hive features    folder.

8.     To add the solution to the farm,
       Add-SPSolution solutionname
       e.g. Add-SPSolution  "D:\mycustomsolution.wsp"

9.    To deploy the solution to the GAC
        Install-SPSolution -identity mycustomsolution.wsp -webapplication http://litware  -GACdeployment

 10. To update the solution
       Update-SPSolution -identiy mycustomsolution.wsp -literalpath "d:\mycustomsolution.wsp" -GACdeployment

11. To uninstall the solution from the web application
      Uninstall-SPSolution -identity mycustomsolution.wp -webapplication http://litware

12. To remove the solution from farm
      Remove-SPSolution -identity mycustomsolution.wsp

Below is the example
Powershell script to install a feature for all the site collections in a farm with known GUID

Add-PSSnapin microsoft.sharepoint.powershell
$webapplications=Get-SPWebapplication
foreach($webapp in $webapplications)
{
$id=$webapp.id;
write-host "processing webapplication with name, id" + $webapp.Name, $id

foreach($site in $webapp.Sites)
{
$name=$site.Name;
write-host "processing site collection -" + $name
foreach($web in $site.AllWebs)
{
write-host "processing web" +$web.title
$features=$web.features;
if($web.features[GUID] -eq $null)
{
enable-spfeature -identity GUID -url $web.url -confirm:$false
}

}
}

}

Sunday, August 26, 2012

SharePoint 2010 OOB approval workflow customization


Hi Guys,

Recently I worked on a requirement to customize the OOB approval workflow in sharepoint designer.

The customer is looking for the  email customization at each stage of the approver  and the workflow initiator.

For e.g., if there are two approvers sequentially and if the approver approves the task, then second approver should know that the document was initially approved by first approver and waiting for the current approval from him self and similar notification to workflow initiator so that the initiator can contact drectly the pending approver to get task immediately.

Below are the steps, I implemented in SharePoint Designer   for acheivimg this customization.

Go to SP designer and open the workflows section of the site.

Select Approval workflow and do right clcik and then do copy and modify option.

After that paste the work flow and change the title and desctiption as required.

Once it it ready, click on Edit Workflow link and then click on the associate workflow part.

image comes here

Here you find 4 links to modify the task options like "Change the behaviour of the single task" , "Change the behaviour of overall task process" etc.

Click on "Change the behaviour of single task" and then do check for the different conditions about the task.

Go to the condition "if task Extenal participant is empty". there is already existing notiffication email action available, Do modify that with your content.

image comes here.

You can address approver  dsiplay name, document link can be embedded here, "Open this task"  link can be added inside the mail body.

image comes here.

Similary if you want notify the initiator about the task approvers, add the similar email action below this and customize the email body accordingly.

image comes here.

Once the approver do the approval/rejection, he can be notified through mail saying that the document is approved/rejected.

This can be done with adding email condition in the below way.

image comes here.