Thursday, April 2, 2009

How to get assembly name for registration ?

When assembly added into global assembly cache and there is need for adding that assembly to web.config assemblies section.

<compilation debug="false">
          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
</compilation>

Now there is need to add System.Web.Extensions assembly , for that you need assembly detail with its public key token to register.

Easiest way to get that detail is 

1. Go to run and type assembly.

run

it will open following window.

window1

2. Now select assembly , for example system.web.extensions , then go to edit menu and select option Copy display name as shown in following image.

window2

3. Now paste data.

image

you get all detail to register assembly. Enjoy… !

Friday, March 6, 2009

Run MSI In Context Of User

Several times to install program you need administrative or other user privileges. For example you take input from user for username and password and run that program in that particular user context.

I faced problem during installing MSI in particular user context or start IIS in context of another user.

I found this solution using command line argument.

1. Inermgr ( Run following command in Command line)

C:\runas /user:administrator “mmc %sysroot%\system32\inetsrv\iis.msc”
Enter the password for administrator :

2. MSI install
C:\runas /user:administrator “msiexec /i <full path of msi file>”

c:\runas /user:administrator “msiexec /i c:\download\setup.msi”
Enter the password for administrator :

For more information just type runas /? on command line.

Thursday, March 5, 2009

Unauthorized (401.1) Exception calling Web Services in SharePoint (.Net Framework 3.5 )

After installing .NET Framework 3.5 sp1 following error may occur while making call to webservice. This thing mostly happen when you are trying to make webservice call using fully qualified domain name instead of IPAddress or Hostheader is used to map request on single port.

I found one strange thing in IIS Log that , for such request it is not sending authentication information to webservice request even though you pass it in NetworkCredential. One solution is to disable integrated authentication and use basic authentication. This will compromise with security but solve problem. Another solution that need to require registry changes. You can find it at following link with grate explanation.

http://www.crsw.com/mark/Lists/Posts/Post.aspx?ID=44
http://support.microsoft.com/default.aspx?scid=kb;EN-US;896861

SPAlert DynamicRecipient On Custom List

In SharePoint default. alert functionality available. You can subscribe Alert on List or ListItem using AlertMe action. But in certain situation you need to automize this alert. Like Alert automatically send to particular user even though he/she did not subscribe event.

There are two way to do . Create feature that receive ItemAdded or ItemUpdated Event , Find out user and email address , send email using SendEmail Functionality of SharePoint.

Another way is use DynamicRecipient property of SPAlert.

Sample List :

list

Here you can see that To Field is type of Person or Group. Send automatic email to user enter ‘To’ Field.

List Entry look Like (Edit View).

alert list entry

Note : UserName must have email id associated with him.SMTP also configured properly for site.

Now run following code against your site. (use console application).

SPSite site = new SPSite("http://yoursite");
SPWeb web = site.OpenWeb();
SPList lst = web.Lists["Alert Test"];
SPAlert alert = web.Alerts.Add();
alert.AlertFrequency = SPAlertFrequency.Immediate;
alert.AlertType = SPAlertType.List;
alert.EventType = SPEventType.All;
alert.DynamicRecipient = "To";
alert.List = lst;
alert.Status = SPAlertStatus.On;
alert.Title = “Auto Email Alert”;
alert.Filter = "<Query><IsNotNull><FieldRef Name='To'></FieldRef></IsNotNull></Query>";            
alert.Update();

You can even use FeatureReceiver to install/ Activate / deactivate this thing as a feature.

Thursday, February 12, 2009

Global Theme Setting for ASP.net 2.0 or Later.

In order to set theme globally for application. There are two ways to do that. one is longer and second one shorter way to do that.

1.
Create App_Themes directory for each application. This is special directory. You can copy Theme over here for each application.

2.
Put New theme under Themes directory of aspnet_clientfile directory.

C:\inetpub\wwwroot\aspnet_client\system_web\2_0_50727

If themes directory not found then create one. For example if theme name is Green then it should be like

C:\inetpub\wwwroot\aspnet_client\system_web\2_0_50727\Themes\Green

This will work for all website that already created. In IIS6 website can be created afterwards. so for that this clientfile does not map to new site, following location must contain themes directory and required theme folder.

C:\Windows\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\Themes\Green

After that run following command from studio command prompt
> aspnet_regiis –c

Above setting works for only IIS6 or previous versino of IIS 5.

Wednesday, February 11, 2009

Kill Process On Remote Machine

It is not recommended that each and every time abort process this way but sometime it is necessary stop some process from executing on remote machine.

There are few useful command for that.

TaskList
Taskkill or tskill

Run following command on command prompt.
> TaskList     ( Current system running process list)

> TaskList /S <system name>
    e.g Remote system name remote1 then
   TaskList /S remote1
   Some of the case you require to pass credential for remote pc in that case use following command.
   TaskList /S remote1 /U <username> /P <Password>
TaskList command is used to get process id that we want to kill.

To Kill process there are two command TaskKill and tskill . I prefer TaskKill over tskill as it gives more command line options.

> TaskKill /PID <process id> ( use to kill perticular process that identified by process id on local machine)

> Taskkill /S <remote pc name or IP Address> /PID <process id> ( kill process that identified by process id on remote machine)

If remote pc require credential than use

> taskkill /S < remote pc name or IP Address> /PID <process id> /U <username> /P <password>

All above command are tested on Windows XP and Windows 2003.
You must require permission to run above command in order to use functionality.

In All Above you can use IP Address instead of remote PC name.

Sunday, February 1, 2009

Difference Between Explicit And Implicit Interface Implementation

Interface can be implemented two ways. Explicitly or Implicitly.
For Example :
public interface IEmployee
{
         string FullName
         {
               get;
               set;
         }
}

Implicit implementation of Interface
public class ImplicitClass : IEmployee
{
     public string FullName
     {
           get ;
           set ; 
     }
}

Explicit implementation of Interface.
public class ExplicitClass : IEmployee
{
    string IEmployee.FullName
    {     
           get ;
           set ;  
    }
}
Here you can see that FullName property does not have access modifier.As this is explicit implementation so it does not allow access modifier.

Now we see what happen when try to create object of both of above class.

ImplicitClass cls = new ImplicitClass();
cls.FullName = “test”;
// Above code works fine

ExplicitClass cls1 = new ExplicitClass();
cls1.FullName = “test”; // error occur

As interface implement explicitly FullName property not available directly to cl1 object b’coz it become private to the Interface type.
img1
By reflection

ImplicitClass cls = new ImplicitClass();
PropertyInfo pinfo = cls.GetType().GetProperty("FullName");
if (pinfo != null)
    {
     pinfo.SetValue(cls, "test",null);
    }       

ExplicitClass cls1 = new ExplicitClass();
PropertyInfo pinfo1 = cls1.GetType().GetProperty("FullName");
            if (pinfo1 != null) // pinfo1 is null in this case.
            {
                pinfo1.SetValue(cls1, "test",null);
            }      

By reflection way also not able to set property as can no available propertyinfo.

Solution for this is , If interface implemented explicit way then cast to Interface type then set property.

ExplicitClass cls1 = new ExplicitClass();
IEmployee emp = cls1 as IEmployee;
emp.FullName = “test”;

if want to access with use of Reflection
ExplicitClass cls1 = new ExplicitClass();                        PropertyInfo pinfo1 = cls1.GetType().GetInterface("IEmployee").GetProperty("FullName");
if (pinfo1 != null)
{
   pinfo1.SetValue(cls1, "test",null);
}      

Note: only choose explicit interface if needed. One such case is if your class previously has property/Event/Method that Interface has also , than to avoid conflict must need of explicit interface implementation.

Please give you further suggestion about this article.