Tuesday, November 22, 2011

C#: Delegate

Here is a simple example of using delegate in C# and it just likes a function pointer in the following code:

  class Demo
    {
        static void Main(string[] args)
        {
            DemoDelegate.process();

            Console.ReadLine();
        }
    }

GridView: dynamic column binding

I try to bind columns to a GridView  dynamically and the code is shown below:

DataTable table = new DataTable();

//add column
table.Columns.Add(new DataColumn("name", typeof(string)));

//add row
DataRow row = table.NewRow();
row["Name"] = "abc";
table.Rows.Add(row);

//bind data to gridView
GridView1.DataSource = table;
GridView1.DataBind();

Saturday, November 19, 2011

ASP.NET: Freeze/Lock Web Page While Loading

When processing a request, web page will be freezed/locked. Hence, users are unable to click any button and just wait.

The following CSS enable Div height 100%:


ASP.NET

C#
protected void submitButton_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(10000); //loading
}

Last but not least, these code works fine for IE6, Chrome and Firefox.

References:
CSS Div Height 100%
How to Freeze Webpage while it is being processed in .Net 2.0 using AJAX?
Lock/Freeze Web Page using jQuery

Sunday, November 13, 2011

Property Bag

SharePoint applications retrieve configuration settings at run time. Configuration database can be stored in the web.config or configuration database. Property Bag can be stored and retrieved configuration settings at the following levels:
-Farm
-Web Application
-Site Collection
-Site
-List

Reference:
SharePoint Property Bag Settings 2010

Managed code and Unmanaged Code

Managed Code
-It compiles to intermediate Language(IL)
-It runs and is managed by Common Language Runtime (CLR)
-The runtime provides services such as security, memory management and threading

Unmanaged Code
-It compiles directory to machine  code
-It does not run and is not managed by the CLR
-It doesn't get the  services of the runtime

Site Definition and Web Template

Web Template is stored in the Solutions Gallery of the site collection and the solution can also be deployed as a sandboxed solutions to other site collections.


Site definition consists of a combination of files that are placed in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates. You can adjust the physical storage capacity required by site collection.
(1) WebTemp*.xml
      Identify the site definitions and configurations and provide information about how they appear in the user interface (UI) to users who are creating new websites.
(2) Onet.xml
     Define the navigation areas, specify the list definitions available in the UI, specify document templates and their files, define the base types for lists, and define configurations and modules for site definitions.


Site Definition vs Web Template 
-The user context in which a web template is deployed does not have to have access to the file system of the servers.
-Custom web templates can be modified without affecting existing sites that have been created from the templates.

Master Page and Page Layout

The top-level SharePoint Server site for a site collection hosted on SharePoint Server 2010 has a special document library called the Master Page and Page Layout Gallery. All page layouts and master pages are stored in this document library. The Master Page and Page Layout Gallery supports versioning and workflow, so you can use those features for your master pages and page layouts.

(By default, SharePoint Server 2010 creates a master page gallery for every site; however, you can create only new pages with the page layouts stored in the master page gallery of the top-level site in the site collection).


Master page provide a consistent look and feel for your site. It contains controls that are shared across multiple page layouts, such as navigation, search and custom field controls.


Page Layout contains field controls and Web Parts. All page layouts reference a master page based on the CustomMasterUrl property of the SPWeb class.


Reference:
SharePoint Page Layouts and Master Pages (ECM)

Solution Deployment Security

There are two type of solution introduced in SharePoint 2010:


Farm Solution
In the manifest file, the solution must define that the assembly be deployed to GAC or Bin folder using DeploymentTarget attribute. Farm solution which is hosted in the IIS worker process (W3WP.exe) , run code that affect the whole farm. IIS application pool recycles before SharePoint retracts or deploys the feature.


1. Deployint Assembly to GAC (global assembly cache)
    Assemblies installed in the GAC run with Full trust and it is accessible to full set of object model. You must reset IIS every time you recompile assemblies.


2. Deploying Assembly to Bin folder using CAS
    Assemblies installed in the Bin folder of the application requires you to assign execution permissions. It is only accessible to subset of object model. You can create a custom policy file and SharePoint defines two trust levels : WSS_Minimal and WSS_Medium (local_drive:\Program Files\Common Files\Microsoft Shared\web server extensions\60\config). There are cases that deploying this solution is not suitable:
(1) Workflow
(2) Event receiver
(3) Timer job


Sandboxed Solution
    Sandboxed solution which is hosted in the SharePoint user code solution worker process (SPUCWorkerProcess.exe), run code that can only affect the site collection of the solution. It is not necessary for the SPUCWorkerProcess process to recycle to load the latest version of the solution. There are the most common things that sandboxed solution cannot  do:
(1) Connect to resources that are not located on the local farm
(2) Access a database
(3) Change the threading model
(4) Call unmanaged code
(5) Write to dick
(6) Access resources in a different site collection


References:
Moss 2007 and Code Access Security
Microsoft Windows SharePoint Services and Code Access Security
Differences Between Sandboxed and Farm Solutions
Sandboxed solutions overview (SharePoint Server 2010)
Chapter 4: Sandboxed Solutions
Farm Solutions

Thursday, November 10, 2011

C#: Polymorphism new vs override

new keyword is used to hide an inherited member from a base class
override keyword is used to provide a new implementation of a member inherited from a base method.

class Demo
{
static void Main(string[] args)
{
Animal a = new Cat();
Animal b = new Dog();
Animal c = new Animal();

a.sayHi();
b.sayHi();
c.sayHi();
Console.ReadLine();
}
}

class Animal
{
public Animal()
{
Console.WriteLine("Animal");
}
public virtual void sayHi()
{
Console.WriteLine("Animal sayHi");
}
}

class Cat : Animal
{
public Cat()
{
Console.WriteLine("Cat");
}

public new void sayHi()
{
Console.WriteLine("Cat sayHi");
}
}

class Dog : Animal
{
public Dog()
{
Console.WriteLine("Dog");
}

public override void sayHi()
{
Console.WriteLine("Dog sayHi");
}
}

The result is shown below:

Thursday, November 3, 2011

Could not load file or assembly Microsoft.SqlServer.Smo

In order to use BAM Alerts in Biztalk Server projects, I need to install SQL Notification Services.

I download needed package from the following three components:

1. Microsoft SQL Server native Client
2. Microsoft SQL Server 2005 Management Objects Collection
3. Microsoft SQL Server 2005 Notification Services Client Components

Go to "C:\Windows\assembly", I can find out the relevant dll whose version is '9.0.242.0'.


After the installation of SharePoint Server 2010, the relevant dll is disappeared.Then I cannot configure BAMTool in Biztalk Server 2010.

Hence, I change the order of my installation.