May 14, 2012

Change the Color of a Column in a List in SharePoint

In this article, we will know how to change the color of a column based upon the values in the column. It is something like “Color Indicator” in SharePoint.
Scenario:
We have a custom list used for Project Tracking. In the list, we have column named STATUS for tracking the project.
Whenever an item in the list is updated with the status in the column, then the background color of the status column should automatically change depending upon the status. Hence it gives a better UI for tracking the status.
Solution:

1. Create a custom list named “Project Tracking System” with the columns such as “Title”, “Description” and Status with the data type as shown below:

Columns with the data types to be created:

2. Now, we will insert 4-5 items in the list created. 
In the above list, we can see that the status column is updated, but it would be good when we have background color of the each status separately. It is gives easy tracking to the users.
3. We can achieve this through JAVA SCRIPT
4. Add a Content Editor Web part below the list as shown below:
5. Now in the content editor web part, add the below java script code (Open the tool pane->Source Editor->Place the Java Script->Click Ok) and save the page.
Add the below code in the script JavaScript tag
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var colorCode = document.getElementsByTagName("td")// finding all the TD tags
var i=0; 
for (i=0;i
{
if (colorCode[i].className=="ms-vb2")  
{ 
if (colorCode[i].innerHTML=="Not Started")//finding the word to which the color has to be set
{ 
colorCode[i].style.backgroundColor='lightblue'; // setting the color depending upon the value
colorCode[i].style.color='Black'; // setting the color of the words inside the content                                     
} 
if (colorCode[i].innerHTML=="Started")  
{ 
colorCode[i].style.backgroundColor='Brown';
colorCode[i].style.color='Black';
} 
if (colorCode[i].innerHTML=="In Progress")  
{ 
colorCode[i].style.backgroundColor='Orange';
colorCode[i].style.color='Black'; 
} 
if (colorCode[i].innerHTML=="Completed")  
{ 
colorCode[i].style.backgroundColor='green';
colorCode[i].style.color='Black'; 
} 
if (colorCode[i].innerHTML=="Deffered")  
{ 
colorCode[i].style.backgroundColor='Red'; 
colorCode[i].style.color='Black'; 
} 
} 
}

6. Now, you can see the status column background is changed depending upon the status inserted for each item as shown below:
It gives good interface to the users and also we can categorize the status easily.
Please free to comment and share the post, if it helps you!

May 10, 2012

Remote Blob Storage (RBS) in SharePoint 2010

In this article, we will know about a new feature in SharePoint 2010 which allows the remote storage in SharePoint.
What is Remote BLOB Storage?
     Ã˜  BLOB – Binary Large Object
Ø  Remote BLOB Storage (RBS) is a library API set that is incorporated as an add-on feature pack for Microsoft SQL Server.
Ø  It can be run on servers with Microsoft SQL Server 2008 R2, SQL Server 2008 or SQL Server 2008 R2 Express. To run RBS on a remote server, you must be running SQL Server 2008 R2 Enterprise edition.
Ø  RBS is not supported for Microsoft SQL Server 2005.
Ø  In Microsoft SharePoint Server 2010, RBS can be used for content databases only.
Why RBS?
It provides the following benefits:
Ø  BLOB data can be stored on less expensive storage devices that are configured to handle simple storage.
Ø  The administration of the BLOB storage is controlled by a system that is designed specifically to work with BLOB data.
Ø  Database server resources are freed for database operations.
When to Go for RBS?
Ø  Large Database of Mostly Binary Data
Ø  Digital Asset Management Databases
Ø  When Storage Tiers Need to be Implemented
Ø  When Storage Needs to be Optimized
You can expect to benefit from RBS in the following cases:
Ø  The content databases are larger than 500 gigabytes (GB).
Ø  The BLOB data files are larger than 256 kilobytes (KB).
Ø  The BLOB data files are at least 80 KB and the database server is a performance bottleneck. Then, RBS reduces the both the I/O and processing load on the database server.
RBS Advantages over EBS (External Blob Storage)
Hope this explains about the basics of RBS in SharePoint 2010.
I came across a good article explaining about Configuring Remote Blob Storage for SharePoint 2010. Here is the link.
Happy Sharing!

May 9, 2012

CAML Query to Get Data from SharePoint List

To know about the Basics of the CAML query read this article.
To know about using CAML query builder to create CAML queries, read this article.
In this article, we will learn how to use CAML query in Microsoft Visual Studio
Scenario:
I have a custom list named “Product List” with the columns named Title, Price, Quantity and Is Available.
I want to retrieve the products with price greater than 1000 and lesser than 10000. Then I have to order the results depending upon the quantity in descending order.
Using the CAML query builder, I have created a CAML query for the above scenario and the query is as follows:
<Query><Where><And><Gt><FieldRef Name="Price" /><Value Type="Number">1000</Value></Gt><Leq><FieldRef Name="Price" /><Value Type="Number">10000</Value></Leq></And></Where><OrderBy><FieldRef Name="Price" Ascending="False" /></OrderBy></Query>

Implementing CAML Query in Microsoft Visual Studio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace UsingCAMLQuery
{
    class Program
    {
        static void Main(string[] args)
        {
            const string camlQuery = @"100010000";
            try
            {
                using (SPSite objSite = new SPSite("sitename"))
                {
                    using (SPWeb objWeb = objSite.OpenWeb())
                    {
                        // Building a query
                        SPQuery query=new SPQuery();
                        query.Query=camlQuery;
                     
                        // Retrieving the data from the List
                        SPList objList=objWeb.Lists["Product List"];
                        SPListItemCollection items= objList.GetItems(query);

                        // Prinitng the header
                        Console.WriteLine("{0,-25} {1,-20} {2,-15} {3}", "Title", "Price", "Qunatity", "Is Available");

                        foreach (SPListItem objListItem in items)
                        {
                            Console.WriteLine("{0,-25} {1,-20} {2,-25} {3}", objListItem["Title"], objListItem["Price"], 
                                                                             objListItem["Quantity"], objListItem["Is Available"]);
                        }

                    }
                    Console.ReadLine(); 
                }
 
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Occured:", ex.Message);
            }
            Console.ReadLine();
        }
    }
}
The full solution can be downloaded from the following link
Please free to comment and share this post if it helps you!

The list cannot be displayed in datasheet view for one or more of the following reasons in SharePoint

I was easily changing my list view by edit in data sheet view and in standard view. 
After sometime, when I tried to edit a SharePoint list in DATASHEET view, I got the following error which doesn't allow me to view the list in the datasheet view and shown up a error as shown below:
Solution:
Clearly, the problem is due to some DLL's in the MS office is creating this problem.
Hence, either of the following solutions will help you to fix this error:
Microsoft Office diagnostics
Run the Microsoft office diagnostics tool by navigating to the following location:
Start -> All Programs -> Microsoft Office -> Microsoft Office Tools -> Microsoft Office Diagnostics
This will repair the office setup installed in the machine. you may see the following screens running once started
Once completed, you will see the following screen:
                            
Installing Office2007 SharePoint Components
I read a wonderful article for this and the link is
Either of the above solutions will help you in fixing this issue.
Hope this saves some one’s time. Happy Sharing!

Using CAML Query Builder for SharePoint

To know about the Basics of the CAML query read this article.
Download Link
Use the following link to download the CAML Query builder.
How to use CAML Query Builder to create a query
Following are the steps for using the CAML query builder to create a CAML query
1. Open the CAML query builder. Type the URL to connect to the SharePoint site and check Credentials of the current user to login

2. Once clicked connect, you will see the following window SharePoint site with all the lists and libraries in the site in a tree view structure which is shown below: 

3. Now we will create a new query on a list named “Product List” as shown below:

4. We will start creating a new query which is as follows:



5. You will find the query being created depending upon your selection from the list

6. Clicking on Execute, you will see the query being executed and the result is being displayed in the result tab as shown below:

The Query created is:
<Query>
           <Where>
                       <Gt>
                              <FieldRef Name="Quantity" />
                              <Value Type="Number">0</Value>
                      </Gt>
          </Where>
          <OrderBy>
                       <FieldRef Name="Price" Ascending="True" />
          </OrderBy>
</Query>
Hence, CAML Query Builder allows us to create the queries very easily so that it can be used in the SharePoint programming.
Now, we will have a question, how to use this query in the Visual Studio to retrieve the data from a list.
To know how to use CAML query in Visual Studio programming, read this article.

Import Excel Sheet to SharePoint List

In this article, we will learn how to export the excel data to the SharePoint list.
Steps:
1. Click on Site Actions -> More Options 
2. Now click on the Lists -> Select Import Spread Sheet from the type -> then Click Create 
3. Give the Name and Description of the List to be created and then browse the Excel Sheet to be uploaded
4. Clicking on Import option, you will find see a popup window opens. Select Range of Cells in the Range Type
5. This option allows you to select the table columns and rows in excel as shown below. After selecting, you will see the selected field’s column and row data being populated in the Select Range field in the popup window
6. Now click on Import in the popup window. Your SharePoint list will be created from the Excel Sheet and the values are also populated as shown below:
You may face some issues while importing the Excel Sheet to SharePoint and the solution is follows:
Error: “Method ‘Post’ of object ‘IOWSPostData’ failed” in SharePoint
Solution:
 Ã˜  Open the Excel Sheet Add-In EXPTOOWS.XLA which will is available at the following location C:\Program Files\Microsoft Office\Office12\1033 by default.
 Ã˜  Press Alt+F11 to display the Visual Basic code editor. Locate the form named "PublishForm" under the folder "Forms" and open the code view of this form.
 Ã˜  Search (Ctrl+F) for the line "lVer = Application.SharePointVersion(URL)" and place a new line "lVer=2" after that line.
 Ã˜  Now try to import the Excel Sheet to the SharePoint, you will not get any errors.

Error: "The specified file is not a valid spreadsheet or contains no data to import"

Solution:
This error occurs when the site you are opening do not have permission to file system. To give permission follow the below steps:
In Internet Explorer click Tools --> Internet Options -> Click Security tab --> Select Trusted Sites --> In the Sites add your URL here.
Now you will be able to import the file properly.
Hope this post helps you! Please free to comment and share this post.

May 8, 2012

CAML Query tutorial for SharePoint

In this article, we will understand the basics of CAML query in SharePoint.
What is CAML?
  Ø  CAML - Collaborative Application Markup Language
  Ø  XML- Extensible Markup Language based query language
  Ø  Used to perform a query operation against SharePoint Lists
How SharePoint List Items are retrieved?
SharePoint List data can be retrieved in any one of the following ways:
1. Using the SharePoint object model – used when code runs on the server (Example: Developing a web part or an application page)
2. Using the SharePoint Lists web service – used when your code doesn’t run on the server where the SharePoint is installed (Example: Developing a windows application)
3. Using Power shell –used mostly by the ADMIN of the SharePoint when they quickly want to retrieve some information from the SharePoint site
How does CAML query looks like?
As I already mentioned, it is XML based query language and it contains tags in it. The root element of the CAML query root element is Query. But it is not necessary to use Query element in the query you form.
Within the Query element you have two elements possible:
1. Where   – to filter the data
2. OrderBy – to categorize the data
A simple structure of the CAML query is as follows:
<Query>
          <Where>
                   <Eq>
                             <FieldRef Name=”FieldName” />
                             <Value Type=”DataType”>Value</Value>
                   </Eq>
          </Where>
          <OrderBy>
                             <FieldRef Name=”FieldName” />
                             <FieldRef Name=”FieldName” />
          </OrderBy>
</Query>
Operators in CAML Query
From the above structure, we came to know that it uses Where and OrderBy elements to retrieve the data from the list.
Let us know about the operators present in the CAML query and its usage:
Inside the Where element
1. Logical Operators - AND, OR
2. Comparison Operators - Listed Below in the table
AND – Which takes two conditions are satisfied
OR – Which takes when either of the conditions is satisfied
Comparison Operators

Inside the OrderBy/GroupBy element
OrderBy – Which orders or sort the data depends upon the field (FieldRef element) given.
GroupBy – Which groups the data depends upon the group by field (FieldRef element) given.
Examples
Logical & Comparison Operators
Use of AND, Gt, Leq
<Query>
<Where>
<And>
<Gt>
<FieldRef Name="Quantity" />
<Value Type="Number">0</Value>
</Gt>
<Leq>
<FieldRef Name="Price" />
<Value Type="Number">2000</Value>
</Leq>
</And>
</Where>
</Query>
Use of OR, Gt, Leq
<Query>
<Where>
<Or>
    <Gt>
<FieldRef Name="Quantity" />
<Value Type="Number">0</Value>
    </Gt>
                     <Leq>
  <FieldRef Name="Price" />
<Value Type="Number">2000</Value>
    </Leq>
               </Or>
       </Where>
</Query>
Use of BeginsWith, Leq
<Query>
<Where>
<And>
     <BeginsWith>
 <FieldRef Name="Title" />
 <Value Type="Text">M</Value>
     </BeginsWith>
     <Leq>
    <FieldRef Name="Quantity" />
<Value Type="Number">1000</Value>
     </Leq>
</And>
</Where>
<OrderBy>
<FieldRef Name="Price" Ascending="False" />
</OrderBy>
</Query>
OrderBy Operator
<Query>
<Where>
<Or>
   <Gt>
<FieldRef Name="Quantity" />
<Value Type="Number">0</Value>
  </Gt>
    <Leq>
<FieldRef Name="Price" />
<Value Type="Number">2000</Value>
  </Leq>
</Or>
</Where>
<OrderBy>
<FieldRef Name="Price" Ascending="True" />
</OrderBy>
</Query>
Is it possible to write this queries without any errors manually?
Yes. But we will know the errors only after executing the program. Hence there is a free CAML query builder which will generate the query easily.
To know about where to download and how to use the CAML Query builder read this article.
To know how to use the CAML query in the Microsoft Visual Studio read this article.

May 6, 2012

Creating FAVICON for WSS 3.0 and MOSS 2007

In this article, we have learned how to Changing the FavIcon in SharePoint 2010.
But there is no favIcon for WSS 3.0 and MOSS 2007 by default. Then how to create favicon for the lower versions of the SharePoint. Here is the solution.
Steps:
1. Open the SharePoint site (WSS 3.0 or MOSS 2007) in SharePoint designer 2007
2. Edit the master page
3. Add the below tag before end of the HEAD tag in the master page
<link rel=”shortcut icon” href=”/SiteImages /favicon.ico” /> 
4. Now save the master page and Check in the page
5. Refresh the SharePoint page, you will see the FAVICON  in the address bar of the SharePoint site.
To know more about:
1. What is favicon ? 
2. Creating favicon
3. Use of favicon
Read this article.

May 5, 2012

SharePoint site continually prompting for passwords

Scenario:
I got a scenario where the SharePoint site is not allowing a user to login to the site even on giving correct username and password.
It is an intranet site and hence it will take the Windows Authentication.
But after 3 consecutive wrong attempts, password should be locked since it is taking the username and password from the Active Directory. It doesn’t happen. I have checked the Active directory and it is unlocked only.

So, what is the problem stopping the user to login to the site? Read the solution below.

Solution:
I have analyzed the problem in the following ways and arrived at the solution. 
The root cause of the issue may be any one of the following issues:
Adding the SharePoint site to the Local Intranet
1. Open IE on your computer, go to TOOLS > INTERNET OPTIONS, and then Select the Security tab. Click on the Local Intranet zone icon, and then the Sites button.
2. You will see a pop up -> Local Intranet -> click Advanced -> Local Intranet -> where you can add the site SharePoint site URL. Example: http://*.domain namehttp://Sitename.domainname. Click the Close and OK.

3. Click OK to exit the Internet Options box, and close all Internet Explorer windows. Open a new Explorer window and try to browse to your SharePoint site. You should be logged in automatically using your Windows credentials.

If you are still unable to login prompt to the site, then follow the next instruction.

Removing the stored old username and password in the control panel
Reason for removing this password:
When we are checking the remember password option while logging into the SharePoint site, then the password is stored in the control panel under 
STORED USER NAMES AND PASSWORDS.
Hence, the SharePoint site is using the older password rather than the newer one (when the password is reset or changed for the particular account). So removing this would help us in resolving this issue.

To remove the saved password, follow the below steps:
In Windows XP, the path is: CONTROL PANEL > STORED USERNAMES AND PASSWORDS.
If you do not have the option you need in the Control Panel, there is a way to bring up the box via the Run box.
Go to START -> RUN and type the following: 
rundll32.exe keymgr.dll,KRShowKeyMgr 
Here you can remove the stored username and password. Now try logging in with the username and password and it will work as expected.

Hope this helps you! Please free to comment and share this post.