Sunday, October 25, 2009

Developing and Deploying Custom Web Parts for SharePoint Portal 2007

Posted on/at 5:09 AM by Admin

   

Overview and difference with SPS 2003:

Developing Web Part for SharePoint Portal 2007 is different as compared to developing for SPS 2003. Web Parts Developed in .Net 1.1 for SPS 2003 used the SharePoint.WebPartPages namespace, however the Web Part in ASP.Net 2.0 is found under theSystem.Web.UI.WebControls.WebParts.

Development of Web Part in VS 2005

To Get Started with creating Custom Web Part for MOSS 2007 in Microsoft Visual Studio 2005, Open the IDE and create a new C# project, Select Class Library as Project Type. Name It as NewWebPart.

clip_image001

Add a reference to the System.Web  from .Net components into the project. The System.Web dll contains the required namespace ofSystem.Web.UI.WebControls.WebParts .

clip_image002

In The Project explorer view rename the Class1.cs with NewWbPart.cs to be consistent with this example; this will result in renaming the Class name as well. With the help of “using” keyword include the namespaces as shown in the code example below. Derive / Extend the NewWebPart Class from the WebPart Class ( System.Web.UI.WebControls.WebParts.WebPart), and add the code as shown below. The CreateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only added a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChildren Method, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method.


using System;

using System.Collections.Generic;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

namespace NewWepPart

{

    public class NewWebPart : WebPart

    {

        protected override void CreateChildControls()

        {

            Calendar cldr = new Calendar();

            cldr.Enabled = true;

            cldr.ShowGridLines = true;

            cldr.ShowTitle = true;

            cldr.EnableViewState = true;

      cldr.SelectedDate = DateTime.Now;

            Controls.Add(cldr);       �

        }

        public override void RenderControl(HtmlTextWriter writer)

        {

            RenderChildren(writer);

        }

    }

}


Build the project and on successful built you are ready to Deploy the Web Part to the Portal Site.

Deployment of Web Part:

In order to deploy a web part to a SharePoint portal 2007 site, we must have the URL of the site to which we want our web part needs to be deployed (displayed in fact). As it  is mentioned earlier that the Web Parts developed in .Net 2.0 environment does have a .CAB project , instead an assembly is created on build of project. Now there are two choices to deploy the assembly to the SharePoint portal directory.

  • Deploy the assembly to the Assembly Folder (GAC) (requires the assembly to be stron named).
  • Put the assembly to the bin folder of the portal directory.

For the sake of simplicity, the later choice is being demonstrated in this example.


Putting Assembly in Bin Folder:

The MOSS 2007 creates every portal in the inetpub\wwwroot\wss folder. The easiest way to find the bin folder from these folder hierarchies is to go from inetmgr console. Locate the appropriate portal (for which u want to deploy the web part), identified with the port number. Right click and have Properties. Under the Home Directory Tab, note the path in Local path text box. Verify if the bin folder exists in the specified path by opening it in browser. If the folder doesn’t exist then create one. Now copy the assembly form the project output folder and paste it in bin folder of portal.

clip_image004

However there is another work around for putting the assembly in to the portal’s bin folder again ad again each time the Web Part Project is built with changes.

Right click on the project name (NewWebPart) in the VS.Net 2005 IDE and click properties. Under  the Build page paste the same path copied from inetmgr console into the Output Path. As shown in figure below. This will result in the latest assembly automatically deployed to the bin folder every time the project is built.

clip_image006

Adding the Safe Control Entry:

Even though the assembly is present in the Portal’s Bin folder, there is another step required to make the Control (Web Part) assembly usable on the Portal Pages. Since the control will need to render on multiple machines in different browsers with as many user accounts as the organizations have. There is a need to declare the control as “safe”. To do so open the web.config file placed under the portal’s directory in the VS.Net 2005 IDE.

clip_image008

Then edit the file in the section of SafeControls, create a new SafeControl entry for our assembly as shown below. Save the file and close it.

<SafeControls>

.

.

.

<SafeControl Assembly="NewWebPart" Namespace="NewWebPart" TypeName="*" Safe="True" />

SafeControls>

Configuring Portal to use NewWebPart

Since now the web part have been written and deployed to the desired portal’s directory. The next task is to use the web part on the Portal’s Site. The Web Part Deployed to the portal can be placed on any site within that Portal. For convenience this NewWebPart is demonstrated to be placed on the home page of default Portal.

Open the portal site in the internet explorer; in this case http://oss1 is the URL for the default portal, ensuring that the current logged in user has the administrative rights on the portal site.

To begin with, the first step is to add the newly deployed web to the Portal’s web part gallery, since the portal is using the configuration databases to keep record of the contents of the portal, our newly created web part’s information doesn’t exist in the database. We need to add the web part to the Web Part Gallery before we can use it.

To do so, the following steps should be followed.

1. Click on the Site Actions button and then select Site Settings.

clip_image010

2. On the site settings page under Galleries column click on the Web Parts.

clip_image012

3. On the Web Part Gallery Page click on the New button, to add the new web part assembly to the gallery.

clip_image014

4. On the New Web Parts page locate the NewWebPart in the list, check the check box on the left and click on the Populate Gallerybutton the top of the page. This will result in the Web Part entry creation in the Web Part Gallery list, and hence it can be used from now on from the gallery. It can be notices easily that the Web Parts developed form the new Frame work of 2.0 have an extension of .webpartafter their names. Whereas in earlier versions, it was a .dwp file. Both the .webpart and .dwp files are the XML definition of the Web Part.

clip_image016

5. Until this step the web part is ready to be used on the site by selecting it from Web Part Gallery. Click on the Site Actions button on the page and then select Edit Page, this will modify the appearance of the page to enable the edit view. In this view Web Part Zones are highlighted so that a user can add a web part to the zone, Click on the Add a Web Part button in the left zone to add the Web Part.

clip_image018

6. Select the NewWebPart from the web part list . it is found under the Misc section and then click on�Advanced Web Part gallery and options.

clip_image020

7. In the�Add Web Part Pane at right , select Home  Gallery and then drag the NewWebPart from the pane into the Web Part Zone.

clip_image021

8. Click on the Exit Edit Mode link on the page and the site will return to the view mode.

clip_image022

 
   

Saturday, October 24, 2009

Map IP Address to a Geographical Location

Posted on/at 2:38 AM by Admin

Introduction

On the Internet there is the concept of web site analytics that helps track all the visitors' activities and usage patterns. One of the dimensions to track is the geographical information of the visitors, which can be obtained by using the IP address information that is collected when a user lands on a Website. In this article, I will describe a simple process that enables your reporting system to display the geographical information of the visitors.

Scope

This article does not describe the process needed to capture the IP information from the user. This process is an application level solution that can be implemented on the front end with software like ASP.Net, PHP etc. The scope of this article is limited to the usage of the IP address to discover the geographical data. This data is composed of the Country, Region, City, Postal code and Area code where applicable. Some countries may not have the concept of postal code.

What is an IP Address?

When a user lands on a web page, the web application has the ability to collect information from this user. One of these data elements is the IP address. The IP address has a format of 192.15.10.125, and it is a logical address assigned to a device. This is what identifies your Internet address, and it is composed of segments that identify your geographical location.

What Do I need to Map an IP Address to a Geo Location?

In order to map the IP address to a geographical representation, the system needs the geographical data mapping. This data is provided by several companies. In this case, we are using the GEOLiteCity data, which is free. To obtain this data, visithttp://www.maxmind.com/app/geolitecity and download the ZIP file which contains two files, Blocks and Location CSV. The block file maps an IP number range to a location. The location file has the geographical information. Please note that there are frequent updates to these files, so make sure you read the description of their services.

In order to import this data to your database, one first needs to create the table definitions. We need to create the Geo Location and Block tables. This are the table definitions: (you can also download the scripts)

clip_image001

Import the data using your preferred method. The first line on the CSV file is a copyright statement. The second line has the column headers, so make sure to skip the first line during the import process. I have also included a visitor log table which can be used to track the user's data. This table is very simple, and it does not include all the possible data elements that can be collected.

Solution

Once the data has been imported, you will notice that the IP address in the data does not look anything like 192.15.10.125. The information is actually stored as an IP number. This numeric value is what allows us to do a range comparison. An IP number range is mapped to a particular location. This is what allows us to do the association, but the first step is to figure out how to convert an IP address to an IP number. This is where a user defined function can help us. We first need to convert the IP address to an IP number by using the ConvertIP2Num function below:

clip_image002

This function first splits the IP address into its four segments (delimited by a dot). This is where XML becomes really handy. We just create an XML string and use the parser to do the split for us by selecting the XML nodes. We use the Row_Number() function to create a factor which will help us arrive to the segment weight (i.e. segment: 192 has rownumber:1 and weigh: 4-1 = 3) . We now apply the conversion formula which consists of assigning a zero based weight to each segment (zero starting from the right segment) and multiplying this segment by (256 ^ n) OR POWER (256,n) where n = weight. The final step is to add all the segment results. For example, IP 192.15.10.125 is converted as follows:

clip_image003

The result is the number that can be used to query the geo tables. To do this, you can create a query similar to the one below which returns the geographical information.

clip_image004

One item to notice here is that the conversion from IP address to number would not perform as well when you are trying to query thousand of rows and using the function to do the conversion at run time. A better approach would be to have an additional column on the table the holds the IP address information. This column can store the IP number as well. (See IPNum column on the Visitor_log Table) This way the import job can populate this field, so there is no performance hit during the query or creation of the report. In addition, by storing both fields (IP Address and Num), you will not have a need to reverse the IP Num to IP Address.

If you do need to reverse an IP Num to IP Address (to validate the process, etc), you can use the ConvertNum2IP function below:

clip_image005

This function just reverses the process by dividing the IP Num by Power(256,n) and subtracting the result from the IP Num. Each segment result is then appended into a string with the corresponding IP Address format.

Conclusion:

With this article, I was able to show a simple process to create your own GEO lookup database and provide a solution to map the IP address to its location information. There are still other items to consider like automating the import process to download the new files, convert the IP address to the IP Num value, integrate this information in a data warehouse, and create reports that will show your marketing team in what regions the customers are located.

Tuesday, October 20, 2009

Facebook forget password Error :)

Posted on/at 6:20 AM by Admin


Hi,

Just i forget my facebook account password and want to reset it. So i go to facebook website and then forget password and then trying to enter the Security Check words like the below screen shot

1

Because I am a developer, I can guess the technical problem as the function which compare the user input  and security check words is wrong .

After you click Reset password, FB will send you an email with code to change your password despite of wrong input words as shown on the above image.

2

May be The below is the technical problem expectation
            The below function of validating word will ignore the last character.

3

I like catching the problems from big companies’ products :)

Hope it being nice post for you.!

Sunday, August 2, 2009

Part IV: Step by step procedure of how to install an assembly

Posted on/at 7:34 AM by Admin


Introduction

Now, we will see how to install an assembly using the merge module witch is a tool provided by the MS Visual Studio 2005. The merge module tool is used to wrap components designed especially in order to be shared later. Components can be dll files or user controls objects that are consumed, in general, by the developer who wants to use or reuse already existing components, for example, he can develop anapplication against given dll files. So, using this method can provide him possibility to enjoy with those dll's or component's services.
Assuming that we want deploy an assembly witch called ClassLibrary1 with this feature:

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace ClassLibrary1

{

public class Class1

{

public Class1()
        {

             MessageBox.Show("You are using ClassLibrary1");

        }

}
}
After building it, we save the project and we add a new one by clicking File, New and Project 
clip_image001
Figure 1

After the merge module project is opened, select Module Retarget able Folder just at right under the File system target machine node, then, right click and select add, then select project output as the figure shows bellow:
clip_image002
Figure 2

Select the primary output element list representing the assembly that we want to deploy. If you want to deploy other elements such as documentation files to get support to the developers or XML serialization assemblies, you can add them with the primary output.
clip_image003
Figure 3

Now, expand the Merge module properties grid and set the author name, for example, "Me" as the figure shows bellow:
clip_image004
Figure 4
There is a property witch I find very useful by the way, I mean, the "Search Path" property used to determine the path used to localize assemblies, files or even merge modules on the development computer.
Now, build the solution and browse to the application directory, the merge module project with name "MergeModule1" is there. Browse to the debug file an open it. A file with *.msm extension is created; this file represents the merge module project output. The mission is not completely accomplished because the merge module can not be installed directly. To install it, we must add an Installer project in order to consume the merge module; in fact, this one can't be installed by its self.
So, add a new setup project by selecting File then Add then New Project, and select Setup Project
clip_image005
Figure 5

Now, select Application Folder then Add then Project output menu item and click on it.
clip_image006
Figure 6

Select the Merge Module 1 project in the combo box list as shown bellow:
clip_image007
Figure 7

Expand the setup properties grid and change the author property "." By "Me" and the Manufacturer property value "." By "Me" before build the project, otherwise, it can not be installed later. Build the setup project. After that, select it, right click and choose install in the context menu and click on it.
clip_image008
Figure 8
The install process will be launched.
clip_image009
Figure 9

After the project deployment, swap to the configuration panel and open add and remove program. You can find the setup 1 among the installed programs.
clip_image010
Figure 10
The developer, or let us say the intermediate user, can browse to %root%\ProgramFiles\Me, there, he can find the new installed dll file.

Part III: Step by step procedure of how to install an assembly

Posted on/at 7:31 AM by Admin


Introduction

We have seen in previous articles how to install an assembly using both, the .NET Framework management console and the Global assembly cache tool provided by the NET Framework. Now we will se how to install a strong named assembly with the simplest manner.
We have seen in a previous article  how one can install a given assembly using the .Net Framework management console the Mscorcfg.msc. Now, we proceed to achieve the same goal but using another tool witch is the Global assembly cache tool cagutil.exe provided by the .Net framework.
To do that, follow those steps:
First of all, let us develop a simple assembly. To do that, follow those steps

  • Create a new class library project and name it myAssembly

clip_image001
Figure 1

  • Add this code to the editor

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace myAssembly

{

public class Class1

{

public Class1()

{

MessageBox.Show("You are using myAssembly");

}

}
}

  • Save the project.
    The GAC accepts only assemblies with strong names; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.

clip_image002
Figure 2

  • Select  the signing tab and then check sign the assembly checkbox

clip_image003
Figure 3

  • Select New in the combo box as shown above. This dialog box appears

clip_image004
Figure 4

  • Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.
    A file looks like this clip_image005 is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe provided by .NET framework.
  • Browse to "C:\Windows\assembly" directory witch looks like bellow:

clip_image006
Figure 5

  • Drag the assembly and drop it in this directory, that's all.

Installing an Assembly: Part II Using the Global Cache

Posted on/at 7:28 AM by Admin

Introduction

We have seen in a previous article  how one can install a given assembly using the .Net Framework management console the Mscorcfg.msc. Now, we proceed to achieve the same goal but using another tool witch is the Global assembly cache tool cagutil.exe provided by the .Net framework.
To do that, follow those steps:
First of all, let us develop a simple assembly. To do that, follow those steps

  • 1. Create a new class library project and name it myAssembly

@1.gif
Figure 1

  • Add this code to the editor

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace myAssembly

{

public class Class1

{

public Class1()

{

MessageBox.Show("You are using myAssembly!!!");

}

}
}

  • Save the project.
    The GAC accepts only assemblies with strong names ; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.

@2.gif
Figure 2

  • Select the signing tab and then check sign the assembly checkbox

@3.gif
Figure 3

  • Select New in the combo box as shown above. This dialog box appears

@4.gif
Figure 4

  • Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.
    A file looks like this small.gif is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe  provided by .NET framework.

  • Build the solution, save the project and close it.

  • Open the console, Start--> Accessories--> Console

  • Browse to your .Net framework directory using the change directory cd command.

  • Tape cagutil -I  myAssembly and the press enter and the windows shell will tell you that the assembly is installed in the assembly cache.

Step by step procedure of how to install an assembly: Part I

Posted on/at 7:27 AM by Admin

Introduction

It is an assembly container provided by the .NET Framework especially to store assemblies shared and used by different .Net applications installed on a given computer or on a given network. It is located in a subdirectory of the root system but it can not be directly accessed except that administrator permission is given before. The GAC is accessed via the .NET configuration management console witch is represented bellow:
1.gif
Figure 1
Assume that an assembly is simultaneously used and/or reused by more than one developer or shared by more than one application. So, it should be shared by them all. Therefore using GAC is a good alternative. It is possible to install the assembly in the GAC and give developers privileges access to the system root rather than to copy it into each development station. It is possible that the assembly cache contains more than one version of the same assembly but it is important to mention in this context that assemblies' names don't have an extension like *.dll or *.exe when are displayed within the GAC list. Only the assembly name appears without any extensions, because when the common language runtime CLR looks for a targeted assembly, it can precise the corresponding assembly according to the application needs. 
When an application is developed against an assembly, it depends on it, therefore it needs to locate it and exploit its services when running. First of all the common language runtime CLR, witch is responsible for executing the application program, verifies if the assembly is already referenced and used, if this is not the case, it search it, at second plan, in the application bin directory, after that, it is checked in the global assembly cache GAC, in a final step, the CLR checks information about the targeted assembly in the configuration file, in this step the code base located in the configuration file gives information about the targeted assembly. When the assembly is not or can not be found, an error occurs. And a message like this can be found in the error list:
2.gif
Figure 2

Where can one find the Global Assembly Cache:

To obtain the assemblies' list in Global assembly cache, follow this path:
Click Start --> Configuration Panel --> Administration tools --> .Net Framework Configuration 
The .NET Framework 2.0 Configuration management console is opened as bellow:
3.gif
Figure 3

Expand the My Computer node within the tree just at right and then select the assembly cache node then click view List of assemblies in the assembly cache hyper link.
4.gif
Figure 4

The assembly list is displayed as bellow:
5.gif
Figure 5

How can one install an assembly in the GAC:

First of all, let us develop a simple assembly. To do that, follow those steps

  • Create a new class library project and name it myAssembly for example.

6.gif6.gif
Figure 6

  • Add this code to the editor.

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace myAssembly

{

public class Class1

{

public Class1()

{

MessageBox.Show("You are using myAssembly");

}

}

}

  • Save the project.
    The GAC accepts only assemblies with strong names ; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.

7.gif
Figure 7

  • Select the signing tab and then check Sign the assembly checkbox.

8.gif
Figure 8

  • Select New in the combo box as shown above. This dialog box appears

9.gif
Figure 9

  • Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.
    A file looks like this small.gif is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe provided by .NET framework.

  • Build the solution, save the project and close it.

  • Switch to the .Net Framework management console and right click on the Assembly cache node, a context menu appears.

  • Click add menu item, the open dialog box appears.

10.gif
Figure 10

  • Browse to the assembly location and then click open. The assembly will be added to the global assembly cache without any problems.

About Me

Developers house is a blog for posting technical articles in different technology like Microsft, Java, Oracle ..etc Microsoft technology includes c#,VB.net,ASP.net,Ajax,SilverLight,TFS,VS.NET 2003,2005,2008,2010 , SQL Server 2000, 2005 , Expression Blend , ...etc I hope it is helpful for all of you and if you are interested to post articles on it, only send me at ahmad.eed@gmail.com