Skip to main content

Mohamed Saleh

Go Search
Home
About Me
  

DreamSpark: Free Development Products For Students!

DreamSpark is a new program from Microsoft that will provide millions of high schools and college students around the world with access to a lot of development and designing tools at no charge!!...

The following products are available right now:

    

 

In addition to all express editions of Microsoft Visual Studio.

 

Right now the students in the following countries will be able to login and verify that they are students and then download all these products for free through DreamPark web site:

(United States, the United Kingdom, Canada, China, Germany, France, Finland, Spain, Sweden, Switzerland and Belgium) Microsoft will be adding more countries throughout the year.

 

Microsoft plans to make the DreamSpark available to all students around the world by 2009.

 

Related Links:

DreamPark Site: https://downloads.channel8.msdn.com/Default.aspx

DreamPark FAQ: https://downloads.channel8.msdn.com/FAQ/Students.aspx

I’m Back!

Well I'm finally back to my blog. It's been a while, but I needed to get back to blogging because I have so much to write about! Just to do a quick update - I'm really happy to announce that I and Muhanad Omar – Jordan SharePoint User Group Leader, Amjad Issa – BizTalk Expert and Active Community Member – Samer Zawati Our new manager, have established Devosis Team. We will hopefully grow and be able to provide organizations with the highest caliber of Microsoft Products Based Consulting Services anywhere!

 

Look out for some new posts very soon…

 

-MAS

Thanks Microsoft for MVP Award

MVPLogoIt was my pleasure to receive email from Microsoft April 1st mentioned that I received the Microsoft 2008 MVP Award for Visual C#.

I would take this chance to thank my wife and my beautiful baby girl Sara for being so patient; at times when I spend whole weeks in front of my computer writing the Visual Studio 2008 Community Material and doing community activities.
I would thank also my good friends Muhanad Omar and Ayman Farouk a lot for all their support too.

Thanks Samer Chidiac my MVP Lead for your continuous support.

I am sure that I will have a very exciting year ahead.


Thanks again to all of the Jordev community members which help me to participate in the community activities and I will continue to do my best to help and assist the best way I know how.

 

Regards,
Mohamed Saleh

Free Visual Studio 2008 Training From Jordev

Visual Studio 2008 has been released already, with formal launch event by Microsoft in the next weeks. Jordev (http://www.jordev.net) User Group will focus on new Microsoft Products this year especially Visual Studio 2008.

On February, Jordev will provide the community with a free training on Microsoft Visual Studio 2008, Your Adoption to 2008 should be rapid, hurry up and register now the seats are limited:

For registration: http://jordev.net/eventReg/trngregistration.aspx

101 LINQ Samples = 101$

A week ago I was looking at the LINQ samples and resources, I find that Microsoft published 101 LINQ samples, but the nice thing about it is the story of the intern who writes these samples and he got 202$ out of Andres Hejlsberg' the Chief Architect of C# and LINQ.

Here are the samples: http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx

And here you can read the whole story: http://microspotting.spaces.live.com/blog/cns!4AE145CB28674D37!211.entry

 

Hope you will enjoy it J

WSS Administration VIA C# How To (1) – Creating Web Application-

It's been a couple of weeks since my last post – I've been traveling to do some work with one of the clients. But I'm back to community and work now, I was thinking in posting series of Visual Studio 2008 and .NET Framework 3.5 Articles and How To(s), but we are in Jordev preparing a custom training material for the community about the Visual Studio 2008 and .NET Framework 3.5, and the materials will be available next week in GeeksConnected and Jordev (http://www.jordev.net) sites.

My friend Muhanad (http://geeksconnected.com/muhanad/) was discussing with me an idea about creating a light desktop application that allows the WSS administrators to create web applications, site collections, sub-sites and lists quickly and effectively without the need to use the WSS web-based administration panel, so I will start posting a series of How To(s) do some of the WSS administration tasks programmatically using C# and SharePoint Administration Object Model.

 

First, I want to focus in the new SPWebApplicationBuilder Object which confuses the SharePoint developers somehow at the first time of using it, this object design is based on the Builder Pattern which is widely used in the software designing best practices, Builder pattern quite confusing, and this confusion appears when a programmer familiar with Factory Pattern start designing or consuming objects designed using Builder Pattern, but there is a very subtle difference between Builder Pattern and Factory Pattern which I will not discuss it here this time.

The SPWebApplicationBuilder provides default settings like the default port and time zone, the SPWebApplicationBuilder also creates an Application Pool for the new IIS Website with the Network Service as the default user.

Using the SPWebApplicationBuilder is easy; just create an instance of the class with passing the local farm to the default constructor, setting the Port (optional), choosing the database name, setting some security settings such as (Allowing Anonymous Access, Using Secure Socket Layer), configuring the application pool name and identity, creating the application, provisioning it, finally and its very important and many developers forgets to do it which is adding the web application to the Web Application List in the Central Administration.

 

The code is very straight forward, I will create the Web Application using a Console Project Template, but you need to add a reference to the SharePoint Administration Object Model:-

  1. After creating a new Console Application in the Visual Studio, in the Solution Explorer, right click the References node, and then click Add Reference.
  2. On the .NET tab select Windows SharePoint Services in the list of components.
  3. Add a using directive for the Microsoft.SharePoint and Microsoft.SharePoint.Administration namespace, as follows:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

 

namespace GeeksConnected.WSSViaCSharp

{

class BuildingWebApplication

{

 

static void Main(string[] args)

{

//Setting the Web Application and Database Name

string strWebAppName = "Am Created Programmatically";

string strDBName = "WSS_Content_GeeksConnecetedWSSAdminViaCSharp1";

 

//Getting an instance of the Local Farm

SPFarm spAdminFarm = SPWebService.AdministrationService.Farm;

 

//Creating an instance of the Web Application Builder

SPWebApplicationBuilder spWebBuilder;

 

//Creating an instance of the SPWebApplication

SPWebApplication spWebApp;

spWebBuilder = new SPWebApplicationBuilder(spAdminFarm);

 

//Setting the Port Number of the Web Application

spWebBuilder.Port = 24521;

 

//Setting the Database Name

spWebBuilder.CreateNewDatabase = true;

spWebBuilder.DatabaseName = strDBName;

 

//Setting the Security Secttings

spWebBuilder.UseNTLMExclusively = true;

spWebBuilder.AllowAnonymousAccess = false;

spWebBuilder.UseSecureSocketsLayer = false;

 

//Setting the Application Pool Configuration

spWebBuilder.ApplicationPoolId = strWebAppName;

spWebBuilder.IdentityType = IdentityType.NetworkService;

 

//Creating the Web Application

spWebApp = spWebBuilder.Create();

 

//Setting the Web Application Name

spWebApp.Name = strWebAppName;

 

//Updating the Web Application Information and then provisioning it

spWebApp.Update();

spWebApp.Provision();

 

//Updating the Appliction Pool Configuration

spWebApp.ApplicationPool.Name = "Programmable Web Pool";

spWebApp.ApplicationPool.Update();

spWebApp.ApplicationPool.Provision();

 

//Adding the newly created web application to the

//List 'Web Applications List' in Central Administation

SPWebService.AdministrationService.WebApplications.Add(spWebApp);

 

//After this do iisreset /noforce

 

}

 

}

}

 

In the portion of the code I show how to update a created web application by using Update and Provision Methods, to me this code above is quicker than using SharePoint Central Administration J

Next time I will go through the Administration Object Model trying to cover the frequently used tasks programmatically…

Cheers,

kick it on DotNetKicks.com
.NET Frameworks Versions Misconception

 

Visual Studio 2008 Ships with the .NET Framework 3.5, there is been some confusion and misconception about what is .NET Framework 3.5 and 3.0, because the Framework 3.5 is not a replacement for the .NET 2.0 and 3.0.

The .NET Framework 3.0 and 3.5 extends the enhancements and the libraries of .NET Framework 2.0, the .NET 2.0 comes with a lot of changes especially into the Common Language Runtime (CLR), the .NET 3.0 was known as the WinFX which was an extension to the .NET 2.0 which contains Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), and Windows CardSpace. This means that .NET 3.5 and .NET 3.0 are just an additive libraries and enhancements to the .NET Framework 2.0.

The .NET Framework 3.5 includes the .NET Framework 3.0 SP1 which includes the .NET Framework 2.0 SP1, so no need to download separate frameworks, which makes the Visual Studio 2008 single unified development environment for multiple versions of the .NET Framework.

Cheers,

Automatically Implemented Properties and Serialization (Part 2)

In the last post I talked about the Automatically Implemented Properties which is very cool productivity feature, and I talked a little bit about the underlying auto generated backing fields, since the post, I tried to play with the auto generated fields to find out a way to write the backing field name in the C# directly, the backing field looks like:

 <Name>k__BackingField

 

The <Name> syntax is not allowed to be used with the C# identifiers, C# 3.0 compiler architects go with this in order not to conflict with any other fields written by the developer.

Now what about the serialization, let's say that I want to add some rules and validation to the getter and setter after implementing it, what will happen to the pre-serialized files after modifying the properties to the old pattern?

When using XML/SOAP serialization we don't have to think a lot about the effects of the new change, but if we are using the Binary serialization then I think we are in a big troubleL!!!

The main difference between the XML and the Binary serialization is that the Binary serialization creates a byte for byte copy of the object's memory image and persist it to the disk which means that the serialized data contains all the members of the object, no matter if they are private or public in addition to the CLR types and the versioning information…which is our problem.

Here's an example serializable class that I will use it to demonstrate this case:

 namespace Properties.AutoImplemented

{

[Serializable]

public class GeeksConnectedMember

{

 

//Read Only Property

public string Name { get; set; }

//Write Only Property

public string Job { get; set; }

public string Email { get; set; }

public DateTime DateOfBirth { get; set; }

 

}

}

 

Here's a trivial implementation of the serialization and deserialization process using the classes included in the Framework:

 /// <summary>

/// This method serialize instance of GeeksConnectedMember with sample data...

/// </summary>

public static void SerializeGeeksConnectedMember()

{

//Definning instance of GeeksConnectedMember class...

GeeksConnectedMember gksMember = new GeeksConnectedMember();

 

//Filling GeeksConnectedMember instance with sample data...

gksMember.Name = "Ammar";

gksMember.Job = "Software Engineer";

gksMember.Email = "Ammar@GeeksConnected.net";

 

FileStream fs = new FileStream(@"c:\GeeksConnectedMemberData.bin", FileMode.Create);

BinaryFormatter bf = new BinaryFormatter();

 

try

{

//Serializing binary image of the GeeksConnectedMember object

bf.Serialize(fs, gksMember);

}

catch (SerializationException ex)

{

Console.WriteLine("Serialization Failed because: " + ex.Message);

}

finally

{

fs.Close();

}

}

 

/// <summary>

/// This method Deserialize the presisited instance of GeeksConnectedMember class...

/// </summary>

public static void DeserializeGeeksConnectedMember()

{

 

//Definning instance of GeeksConnectedMember class...

GeeksConnectedMember gksMember = new GeeksConnectedMember();

 

FileStream fs = new FileStream(@"c:\GeeksConnectedMemberData.bin", FileMode.Open);

BinaryFormatter bf = new BinaryFormatter();

 

try

{

//Deserializing binary image of the GeeksConnectedMember object

gksMember = (GeeksConnectedMember)bf.Deserialize(fs);

Console.WriteLine("GeeksConnected Member Name : " + gksMember.Name);

Console.WriteLine("GeeksConnected Member Job : " + gksMember.Job);

Console.WriteLine("GeeksConnected Member Email : " + gksMember.Email);

}

catch (SerializationException ex)

{

Console.WriteLine("Deserialization Failed because: " + ex.Message);

}

finally

{

fs.Close();

}

 

}

 

And now let's take a look to the GeeksConnectedMemberData.bin contents:

 ♀☻ PAutoImplementedProperties, Version=1.0.0.0, Cul

ture=neutral, PublicKeyToken=null♣☺ 'Properties.AutoImplemented.Geeks

ConnectedMember♦ §<Name>k__BackingField¶<Job>k__BackingField▬<Email>k__Back

ingField∟<DateOfBirth>k__BackingField☺☺☺ ♪☻ ♠♥ ♣Ammar♠♦ ◄Softwar

e Engineer♠♣ ►Ammar@GeeksConnected.net ♂

 

As I mentioned before the binary serialization persist all the private and public members of the object, we can notice here the underlying auto generated backing fields' names into the content of the deserialized file.

Here's below the GeeksConnectedMember class with the old pattern of implementing the properties:

 /// <summary>

/// This is the classical class of GeeksConnectedMember using trivial way of implementing properties.

/// </summary>

public class GeeksConnectedMember

{

 

private string _name;

private string _job;

private string _email;

private DateTime _dateofbirth;

 

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

 

public string Job

{

get

{

return _job;

}

set

{

_job = value;

}

}

 

public string Email

{

get

{

return _email;

}

set

{

_email = value;

}

}

 

public DateTime DateOfBirth

{

get

{

return _dateofbirth;

}

set

{

_dateofbirth = value;

}

}

 

}

 

If we try to use the classic version of properties with the Pre-Serialized files we will see no results.

As we see in the previous samples, it's not recommended to use the automatic properties when the Binary Serialization is required.

 

Cheers,

Automatically Implemented Properties (Part 1)

C# 3.0 is the new version of the language includes many new features inspired by functional programming language, to not be confused the 3.0 means the version of the language specification and not the .NET Framework version.

I will talk here about the Auto implemented properties, and I want to mention here that it's not an enhancement on the language that's reflect an enhancement on the generated intermediate language (IL); it's just a new compiler feature or we can say it's a kind of productivity enhancement and can replace one of the code generation tools features.

It's cool to have a new quick way to add new properties without the need to write the getter and setter declarations.

Every developer has written entity or model class before, these classes which contains the trivial properties with both getter and setter for each fields.

The classic way of adding properties is like the following simple example:

namespace Properties.Classic

{

 

/// <summary>

/// This is the classical class of GeeksConnectedMember using trivial way of implementing properties.

/// </summary>

public class GeeksConnectedMember

{

 

private string _name;

private string _job;

private string _email;

private DateTime _dateofbirth;

 

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

 

public string Job

{

get

{

return _job;

}

set

{

_job = value;

}

}

 

public string Email

{

get

{

return _email;

}

set

{

_email = value;

}

}

 

public DateTime DateOfBirth

{

get

{

return _dateofbirth;

}

set

{

_dateofbirth = value;

}

}

}

}

 

The Automatic Properties delegates the writing of the getter and setter for the private fields and generates backing fields for this target.

 

Below the GeeksConnectedMember class implemented using the Automatic Properties:

 namespace Properties.AutoImplemented

{

public class GeeksConnectedMember

{

public string Name { get; set; }

public string Job { get; set; }

public string Email { get; set; }

public DateTime DateOfBirth { get; set; }

}

}

 

Let's go internally and check out how the compiler treats the previous classes in the classic and the new version.

The easiest way to slice the properties is to disassemble it using the ILDASM utility, here's the IL generated by the C# compiler for the getter accessor of the Name property in the classic version of GeeksConnected Member:

 .method public hidebysig specialname instance string get_Email() cil managed

{

.maxstack 1

.locals init (

[0] string CS$1$0000)

L_0000: nop

L_0001: ldarg.0

L_0002: ldfld string Properties.Classic.GeeksConnectedMember::_email

L_0007: stloc.0

L_0008: br.s L_000a

L_000a: ldloc.0

L_000b: ret

}

 

And here's the generated IL of the new version of GeeksConnectedMember with the automatically implemented properties:

 .method public hidebysig specialname instance string get_Name() cil managed

{

.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()

.maxstack 1

.locals init (

[0] string str)

L_0000: ldarg.0

L_0001: ldfld string Properties.AutoImplemented.GeeksConnectedMember::<Name>k__BackingField

L_0006: stloc.0

L_0007: br.s L_0009

L_0009: ldloc.0

L_000a: ret

}

 

And now we will find that the C# compiler generates the backing field which named <Name>k__BackingField this field holds the data of the property like the private fields we defined above. The compilers architect pay attention for something very important which is the naming style of the auto-generated properties because the '<Name>' prefix is not allowed to be used in any C# identifier.

If you need to have a read-only property you can use the access modifiers with the getter and setter like the following:

 //Read Only Property

public string Name { get; private set; }

//Write Only Property

public string Job { private get; set; }

 

Simply the automatic implemented properties are the quickest way to write the trivial properties of the classes.

 Latest Posts

Thanks Microsoft for MVP AwardUse SHIFT+ENTER to open the menu (new window).
DreamSpark: Free Development Products For Students!Use SHIFT+ENTER to open the menu (new window).
I’m Back!Use SHIFT+ENTER to open the menu (new window).
Free Visual Studio 2008 Training From JordevUse SHIFT+ENTER to open the menu (new window).
101 LINQ Samples = 101$Use SHIFT+ENTER to open the menu (new window).
WSS Administration VIA C# How To (1) – Creating Web Application-Use SHIFT+ENTER to open the menu (new window).
.NET Frameworks Versions MisconceptionUse SHIFT+ENTER to open the menu (new window).
Automatically Implemented Properties and Serialization (Part 2)Use SHIFT+ENTER to open the menu (new window).
Automatically Implemented Properties (Part 1)Use SHIFT+ENTER to open the menu (new window).

 ‭(Hidden)‬ Admin Links