Sharepoint 2010 Build Error: Failed to extract the cab file in the solution

As usual we faced some problems in SharePoint 2010 during building without more clarification or description to know what is the error message means?  so you have to investigate and search by yourself which part of the solution this problem? How to fix it?

but furthermore i am still like Microsoft :)

Error Message: Error occurred in deployment step 'Add Solution': Failed to extract the cab file in the solution.

This happen with me during deployment because there is image name in my layout folder contain brackets like "add(2).png" So you have to check if you have any files with special characters including brackets ' copy (2) filename ' and remove them.

Solution: To work around this problem, remove any parentheses in the names of SharePoint project items.

Here’s a list of some problems:

Difference between int.Parse() and Convert.ToInt32

9. April 2011 10:36 by Mahmoud Farhat in C#, C#, C#, C#  //  Tags:   //   Comments (0)


This post just a slight tip for showing the difference between Int32.parse(string) and Convert.ToInt32(string)



- Int32.Parse(string str) method converts the string representation of a number to integer 32 bit.
- when str is a null reference it will throw ArgumentNullException.
- if str is other than integer value it will throw FormatException.
- when str represents a number less than MinValue or greater than MaxValue it will throw OverflowException.


- Convert.ToInt32(string str) method converts the string representation of a number to integer 32 bit.
- when str is a null reference it will return 0 rather than throw ArgumentNullException.
- if str is other than integer value it will throw FormatException.
- when str represents a number less than MinValue or greater than MaxValue it will throw OverflowException.

Content Query Web Part with formatted date in Sharepoint 2010

27. March 2011 21:56 by Mahmoud Farhat in   //  Tags:   //   Comments (0)
In this post I am going to show step by step how to format the datetime in your own item style in sharepoint 2010

1-     Open your top-level site in Sharepoint Designer, click “All Files – Style Library – XSL Style Sheets – ItemStyle.xsl” and click Edit, I prefer to get a  backup from this file before do any changes.

In the top of the file, add this line so we can format the date further down the road: 
3-     Add this at the bottom of the variables section:
<xsl:variable name="Created"> 
<xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1033 ,'dd/MM/yyyy')" />
The following lists of the language packs that are available for Office SharePoint Server 2010.
Arabic     Saudi Arabia (Hijri)    1025
English    United States               1033
 4-      Then you can use the variable
	<strong><xsl:value-of select="$Created"/></strong>
Full Sample:
<xsl:template name="Test_template" match="Row[@Style='Test_template']" mode="itemstyle">
     <xsl:variable name="CurrentDate">
         <xsl:value-of select="ddwrt:FormatDateTime(string(@Date) ,1025 ,'yyyy/MM/dd')" />
     <div style="width:400px;  height:100px;text-align:right;">
                     <div style="text-align:right;">
             <xsl:value-of select="$CurrentDate"/>

Using Null in an expression always returns null in SQL !!!

13. March 2011 08:38 by Mahmoud Farhat in SQL  //  Tags:   //   Comments (0)

Please check the below table and just remember that NULL means “unknown”


The expressions in this list always return NULL:


If A and B are NULL, then:



1 + 2 + 3 + A


If A is unknown, then 6 + A is also unknown.

'Home ' || 'sweet ' || A


If A is unknown, 'Home sweet ' || A is unknown.

MyField = A


If A is unknown, you can't tell if MyField has the same value...

MyField <> A


...but you also can't tell if MyField has a different value!

A = B


With A and B unknown, it's impossible to know if they are equal.

not (A)


If A is unknown, its inverse is also unknown.

The above table will help you at many cases that you want to use null so we will take a sample to make this list very easy and clear for you, like If you are looking to create SQL query for using it in search to get data from employee table according to some search criteria

Employee Table:




Karim Hasan




Ola Ali


 1- This query return all rows just if the name is equal "Karim"


Set @name = 'Karim'
 from Employee where EmployeeName = @name

ID            EmployeeName
2              Karim

2- This query return all rows contains name "Karim"


Set @name = 'karim'
 from Employee where EmployeeName like '%' + @name + '%'

ID            EmployeeName
1              Karim Hasan
2              Karim

The above samples are not my point there are jsust initiative my point is, if you want once the user pressed on the search button in you application without enter any data like "Employee Name" then return all the employees from the employee table and this means you are going to set @name parameter with NULL value (Set @name = null), how can we do that??


Honestly there are many ways to do that and I will list two samples one of them is the best at latest for me depend in NULL expression and I prefer to use it in my work.


Sample 1:


Declare @name varchar(20)
@Sql varchar(1000)

set @name = 'Karim'
@Sql ='select * from Employee where 1 = 1'

If (@name is not null)

     select @Sql = @Sql + ' and EmployeeName like ''%' + @name + '%'''

Sample 2:

Declare @name varchar(20)

@name = 'Karim'
* from Employee where EmployeeName = IsNull ( '%' + @name + '%', EmployeeName)

when you take a look in this statement at the first time "IsNull ( '%' + @name + '%', EmployeeName)" you will say how isnull function will return null without to check in this char '%', but as we list before in the above table that if you are using Null in an expression returns null

Select  1 +2
Result: 3
Select 1+Null
Result: Null
Select  '%' + Null
Result: Null

I prefer the sample 2 by using NULL expression because it is very easy and as you see we don't need to write many lines of code to write quires for search.

Good luck, and I hope this information is helpful to you and Please feel free to write your comment.

C# 4.0 optional parameter and named arguments

17. January 2011 00:25 by Mahmoud Farhat in C#, C#, C#, C#, C#, C#, C#, C#  //  Tags:   //   Comments (0)

C# now supporting optional parameter in methods, constructors, indexers and this is new feature coming in C# 4.0 with additional feature named arguments

- Optional parameter:

The optional parameters idea is that the arguments on a method may have default values and therefore it is unnecessary to pass those arguments in a method if you are willing to accept those default values.  And this may be helping you when you are going to overload methods several times.


public static void UserInfo(string name, int age, string country = "Egypt”) {
            Console.Write(" Name:{0} \n Age:{1} \n Country:{2}",name,age,country);

In the method above we set a default value in country, which means it can now be used optionally by caller of the method


The country is not specified and this means you are accept to take the default value and then you can handle you work flow as you.


or you can override the country by passing country name  



- Named parameters

Sometime you have multiple optional parameters

public static void UserInfo(string name, int age, string country = "Egypt", _

       string city = "Cairo"){}

And the question here how do you specify the value of city without specify the value of county??!!

We can do that by “Named Parameter”, and this means that The parameter for each argument can be specified by parameter name



The optional parameters must come at the end of the list of method arguments. And you have to specify all your required arguments in the method first and then list the optional arguments last just like above samples.