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:
http://msdn.microsoft.com/en-us/library/ee330922.aspx

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)

- 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)

- 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.

2-     
In the top of the file, add this line so we can format the date further down the road: 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
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')" />
</xsl:variable>
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')" />
     </xsl:variable>
     <div style="width:400px;  height:100px;text-align:right;">
                     <div style="text-align:right;">
             <xsl:value-of select="$CurrentDate"/>
         </div>
     </div>
 </xsl:template>

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:

Is:

Because:

1 + 2 + 3 + A

NULL

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

'Home ' || 'sweet ' || A

NULL

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

MyField = A

NULL

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

MyField <> A

NULL

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

A = B

NULL

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

not (A)

NULL

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:
 

ID

EmployeeName

1

Karim Hasan

2

Karim

3

Ola Ali

 

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

 

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

Result
--------------------------
ID            EmployeeName
2              Karim


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

 

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

Result
--------------------------
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)
Declare
@Sql varchar(1000)

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

If (@name is not null)
Begin

     select @Sql = @Sql + ' and EmployeeName like ''%' + @name + '%'''
End
exec
(@Sql)


Sample 2:

Declare @name varchar(20)

set
@name = 'Karim'
select
* 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.

Example:

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

UserInfo(“Mahmoud”,30); 

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.

Output:
Name:Mahmoud
Age:30
Country:Egypt

or you can override the country by passing country name  

UserInfo(“Mahmoud”,30,”USA”); 

Output:
Name:Mahmoud
Age:30
Country:USA

- 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

UserInfo("Mahmoud",30,city:"Alex");


Note:

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.