This blog is moved to
http://amalhashim.wordpress.com

Tuesday, November 3, 2009

Using XPath in C#

In this blog I am going to give an overview of how we can easily parse and get the data from an XML file. For demonstrating, I have created a sample XML file listed below.

<?xml version="1.0" encoding="utf-8" ?>
<
Employees>
<
Employee>
<
Name>Amal</Name>
<
Age>26</Age>
<
Address>333 Indiana Street</Address>
</
Employee>
<
Employee>
<
Name>Munna</Name>
<
Age>20</Age>
<
Address>222 West Region</Address>
</
Employee>
</
Employees>

Add the following namespace in your application

using System.Xml.XPath;

Now we can open the XPathDocument object as follows

XPathDocument Doc = new XPathDocument("emp.xml");

Once this is done, we need a XPathNavigator

XPathNavigator navigator = Doc.CreateNavigator();

Using this navigator object, we can traverse through the document. We can provide XPath expressions as shown below

XPathNodeIterator iterator = navigator.Select("/Employees");
while (iterator.MoveNext())
{
Console.WriteLine(iterator.Current.Name);
Console.WriteLine(iterator.Current.Value);
}

1

Try changing the XPath expression as demonstrated below.

iterator = navigator.Select("/Employees/Employee");
iterator = navigator.Select("/Employees/Employee[Age>22]");
iterator = navigator.Select("/Employees/Employee[Age>22]/Name");
Hope this helps :-)

SQL Server 2008 Installation

Start the SQL Server 2008 installation by clicking the following icon

3

This will bring up the following screen

1

From right pane, click on “Installation link”. You will get the following screen.

4

From the left pane, click on the link “New SQL Server stand-alone installation or add features to an existing installation”. The 1st action performed by the installer is checking the setup support rules.

5

You can get a detailed report, by following the link “View detailed report”. Click OK.

6

Now we need to specify, which version we are going to install. If you have purchased SQL Server 2008 then enter the product key. Click Next.

7

Accept the agreement and Click Next.

8

Hit Install.

9

For detailed report, follow the link “View detailed Report”. Click Next.

10

Select the features you want to install and Click Next.

11

Select the instance name and Path. Click Next.

12

From the screen we can understand that the minimum disk space we need in C drive is 2040. Click Next.

13

In this screen we can specify on which account each of the SQL services should run. Click Next.

14

Specify the Authentication Mode. If you want to add the Current User in the SQL Administrators list, then Click Add Current User. You can enable the FILESTREAM feature by opening the FILESTREAM tab.

Once you are done, Click Next.

15

Provision the accounts that require have admin privileges. Click Next.

16

In this screen, we must specify how the Reporting Server must be configures. The available options are “Native Mode”, “Sharepoint Integrated Mode”. If you want to access the data from sharepoint lists, then select Sharpoint integrated mode. Else Native mode will be fine. Click Next.

17

Click Next.

18

Click Next.

19

Click Install.

20

Installation Completed. Click Next.

21

Monday, November 2, 2009

Sharepoint and Silverlight - 1

As part of setting up the environment we must be careful to do the following points

Point #1

Changing the MIME type in IIS to support Silverlight application. This can be done as follows

1. Open run window from Start Menu

2. Enter inetmgr and click OK

3. This will bring up the Internet Information Services Manager. From the folder structure on the left side, select the site which is your Sharepoint application.

4. Now from the right pane select "Mime Types" and "Open Feature"

5. In Mime Type View, Click Add, add the file extension, and type .xap as the file extension and "application/x-silverlight-2" as the Mime type.

Point #2

In the web.config of your Sharepoint application, add the required configurations.

Point #3

Make sure the System.Web.Silverlight.dll is in the GAC

Installing Sharepoint Extensions for VS 2008 in XP/Vista

The extensions installer can be downloaded from the following location

Download

Once you have downloaded. You need to modify the registry, for doing that follow the below steps

1. Open run window from Start Menu

2. Enter Regedit and Click OK

3. Open the following location

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\

Now create a new Key named “12.0”

Under 12.0 create a new String “Sharepoint” and give the value “Installed”

4. Now run the installer you have downloaded from the link above.

Sharepoint Top-Level Object Model

Amal Hashim

Building and Deploying a Web Part

In this article am going to explain how we can develop a simple web part and deploy it in Sharepoint.

There are two way we can build a web part.

1. Using Sharepoint extensions for Visual studio.
2. Developing a Class library and manually deploying it in Sharepoint.

Sharepoint extensions for visual studio can be downloaded from the following location

Download

Once you have installed the extension, from Visual Studio->File->New Project->Share Point->Web Part

This will provide a template with all setting ready for building a web part. Once you have done with the web part, you can deploy it directly from Visual Studio. For doing that open the properties dialog by right click the project from solution explorer, go to the debug tab and enter the sharepoint web application URL and save the settings. You can use the same right click context menu for deploying the web part directly to sharepoint server by clicking the deploy menu item.

Manual development and deployment steps

  1. From visual studio File->New Project->C#->Class Library

  2. Right click and Add Reference of System.Web

  3. Rename Class.cs to NewWebPart.cs

  4. Open NewWebPart.cs and add the following code

  5. using System;
    using System.Collections.Generic;
    using System.Text;

    namespace NewWebPart
    {
    public class NewWebPart: System.Web.UI.WebControls.WebParts.WebPart
    {
    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
    writer.Write("Hello World!!!");
    }
    }
    }

  6. Right click project->Properties->Signing, and sign the assembly with a key

  7. Now build the project

  8. Open visual studio command prompt and use the following command

  9. gacutil /i C:\bin\NewWebPart.dll
    Replace C:\bin\NewWebPart.dll with the location of NewWebPart.dll in your machine

  10. Open your sharepoint web application's web.config file and add the following entry

  11. <SafeControl Assembly="NewWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=902d73ff104745c3" Namespace="NewWebPart" TypeName="NewWebPart" Safe="True" />

    Replace 902d73ff104745c3 with the token of assembly. You can find it by opening c:\windows\assembly

  12. Open Site Setting from Site Actions menu

  13. Click on Web Parts

  14. Click New

  15. Select NewWebPart.NewWebPart and Click Populate Gallery

    Now you can add web part on your site by editing the page.

    That's it!!!

SQL Server 2008 Installation Pre-Requisites

In this blog series, I am going to explain in details about how we can install SQL Server 2008 dev edition on a windows XP box.

My current configuration is

  • Windows XP SP3
  • Visual Studio 2008 (No service pack installed)
  • .Net Framework 3.5 SP1

Once I started installing SQL Server 2008 on my dev box, I started complaining that it need the KB(KB942288-v2) to be installed.

warning

This KB installer is a hot fix for Windows installer. I clicked Ok and an installer window comes up, and installed that hot fix. Once this hot fix is installed, we needs to reboot our machine.

reboot Once the system reboots, execute the SQL 2008 installer. This will bring up the following screen.

1

In this screen if you notice, there is an option called “System Configuration Checker”. Click on that link, which will bring up a utility that can scan and show the components which has passed/failed as shown below.

2

Now, we are ready to start our SQL Server 2008 installation :-)