Thursday, October 9, 2008

Change The Location Of GAC

By default whne .NET framework install then it will install global assembly cache to operating system root drive:\windows\assembly.

In order to change its location you need to update following registry.


Add CacheLocation (REG_SZ) key and set it to new location.

Suppose your new location is c:\bkfrm then CacheLocation c:\bkfrm. Now .NET framework search for assembly directory inside c:\bkfrm.

Use code to backup assembly and give source directory c:\windows\assembly and destination (f you take c:\bkfrm) then c:\bkfrm\assembly. (assembly folder must required in any of case).

Note: It is required to change in registry so it may cause problem.

Global Assembly Cache Directory Structure and Backup

Whenever .NET framework install on PC. There is one specific directory created called Global Assembly Cache.It contains all assemblies that available to all application on machine.

To open global assembly cache go to run and type assembly or if your sysroot in C drive then go for c:\windows\assembly.


It is a special directory so it look like this. By default it store data in directory structure.Please look at following image.


To Copy global assembly cache you can use following code in C# 2.0.

static void Main(string[] args)
            string assemblyfolderpath = "d:\\windows\\assembly";
            string copypath = "c:\\newtest123";
            DirectoryInfo dir = new DirectoryInfo(assemblyfolderpath);

        static void ReadDir(DirectoryInfo dir,string copypath)
            if (dir != null)
              FileInfo[] infos =  dir.GetFiles();
              for (int i = 0; i < infos.Length; i++)
                  infos[i].CopyTo(copypath + "/" + infos[i].Name);
              DirectoryInfo[] dirs = dir.GetDirectories();
              for (int i = 0; i < dirs.Length; i++)
                  Directory.CreateDirectory(copypath + "/" + dirs[i].Name);
                  ReadDir(dirs[i],copypath +"/"+ dirs[i].Name);

This is the way by which you can create copy of Assembly.

Tuesday, October 7, 2008

The File Exists. (Exception from HRESULT: 0x80070050)

This error i got when i removed Active Directory from PC. Actually first i install active directory. Then on next day iremoved it from PC. So it remove all account from my PC. Only administrator are present over there. So none of other program working. Even IIS stop working. I removed iis and then reinstall it . Then configure .net by using aspnet_regiis command. This will create ASPNET user account. Also Reinstallation of IIS create IUSR_ <Machine Name> account.After everything runs ok sharepoint stop working . I removed sharepoint and reinstall it. In Installation of sharepoint i choose same database as previous installation.So it create all sites in IIS. After successfull installtion Central Admin so me error message The File Exists. (Exception from HRESULT: 0x80070050). So for solution i create one user in system with adiminstrators as group and try to login using that user. ( I am not able to login using administrator account).

After this i choose each of application and add new user as a secondary account.

Central Administration > Application Management > Site Collection Owners

Change each of site collection secondary user. This solution works for me.May be cause is different in certain condition.(Possible then restart PC after user setting in all site collection).Cause of problem is related to SID.

Sunday, October 5, 2008

Retrieve SharePoint List With Folders and Files ( Tree Structure)

To retrieve SPList structure wise use SPQuery to retrieve childitems.

There is property called FileSystemObjectType of SPListItem that identifies the current item (Either Folder or File).

SPSite site = new SPSite("http://localhost:43588");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["WebLink List"];
Response.Write("<span style='padding-left:0px'>" + list.RootFolder.Name + "</span>" + "</br>");
GetChildItems(list, list.RootFolder,10);

GetChildItems is a recrusive function.

GetChildItems Function

private void GetChildItems(SPList lst , SPFolder folder,int padding)
       SPQuery query = new SPQuery();
       query.Folder = folder;
       SPListItemCollection col =  lst.GetItems(query);
       foreach (SPListItem item in col)
           if (item.FileSystemObjectType == SPFileSystemObjectType.File)
               Response.Write("<span style='padding-left:"+ padding +"px'>"+item["URL"]+"</span>"+ "</br>");
           else if (item.FileSystemObjectType == SPFileSystemObjectType.Folder)
               Response.Write("<span style='padding-left:" + padding + "px'>" + item.Title + "</span>" + "</br>");
               GetChildItems(lst, item.Folder,padding+30);

Saturday, October 4, 2008

Event Null Checking In VB.NET Before It Raise

For Example In C#

class MyClass
        public delegate void MyEventHandler(int i);
        public event MyEventHandler MyEvent;

        public MyClass()

        public void FireEvent()
            if (MyEvent != null)

In above example we check  MyEvent has reference or not by checking if(MyEvent != null) in FireEvent Method. So Event only raise when it has reference.

In VB.NET raiseevent internally check this thing. but if you want to manually check then use following method.

VB.NET Example:

Public Class MyClass1
    Public Event MyEvent(ByVal i As Integer)
    Public Sub New()
    End Sub
    Public Sub FireEvent()
        If MyEventEvent IsNot Nothing Then
            RaiseEvent MyEvent(10)
        End If
    End Sub
End Class

In that is not necessary to create delegate. You can directly create event. If you want to check that event has reference or not if you have to Add “Event” extra word at the end of Event Name . In above example out event is MyEvent so we did check MyEventEvent is nothing or not. We can not directly check MyEvent is not nothing in VB.NET.

One more thing to know allow us to create event directly ( Without creating delegate). But implicitly it create delegate that has same name like MyEventEvent. Suppose you declare event Add then AddEvent delegate automatically created. (Please see below image).