Thursday 28 July 2011

Services Unavailable: While Opening Central Administration site in Sharepoint

Hi All,

All of must see this error "Services Unavailabe", while accessing central admin in Sharepoint. I got an error message saying: Service Unavailable in the internet explorer. But my other MOSS sites were working perfectly fine!

I went into my IIS application pool for Central Administration web application, it had stopped without any reason. I tried to start it, and it would start but it did'nt solve the problem. I was stuck in the same loop i.e Service Unavailable when trying to access Central Admin web application.
Then i figured out that i need to change my System Account password which had full control to Central Admin web application. How do i do that ? Be careful, follow the steps properly:
Solution: Change the passwords if you receive a "Service Unavailable" error when trying to access Central Administration. Change the passwords for the Central Administration Web application pool identity and the Windows SharePoint Services Timer service by using the command line
  1. On the computer running the Central Administration Web site, open the command line and navigate to the Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN folder.
  2. At a command prompt, type the following command, and then press ENTER:
    stsadm -o updatefarmcredentials -userlogin domain\username -password newpassword
    userlogin is the server farm account.
    For additional information, see Updatefarmcredentials: Stsadm operation (Windows SharePoint Services).
  3. You must restart the Web application pool for the changes to be saved. At a command prompt, type the following command, and then press ENTER:
    iisreset /noforce
  4. As an additional step, you can even Go to Start->Run and type services.msc and restart the Windows Timer services(which should use the newly changed password).
  5. Try accessing the Central admin site and it should work normally as before.



Thanks

Wednesday 27 July 2011

Get list data using SharePoint Object Model

Get list data using SharePoint Object Model:

This article explains how you can use the SharePoint Object Model(MOSS 2007) classes like SPSite and SPWeb in C# or Visual Basic code to fetch data from a custom SharePoint list.

Problem:
You want to get data on the basis of url (including siteurl+listname) from the custom SharePoint list.

Resolution:
In this scenario, we can use SharePoint Object Model classes to access data from custom SharePoint list.

public static bool CheckListExists(string listName, SPWeb web,ref SPList list)
     {
         try
         {
             //---Check list exist or not
             if (web.Lists[listName]!=null)
             {
                 list = web.Lists[listName];
                 return true;
             }
             return false;
         }
         catch (ArgumentException ex)
         {
             return false;
         }
         catch (Exception ex)
         {
             return false;

         }
     }


Above function used to check list exist in the SharePoint site or not.

public static void  GetListData(string listUrl)
     {
         SPList objList = null;
         char [] chrSplitter={'/'};
         try
         {
             listUrl = listUrl.TrimEnd(chrSplitter);
             string[] arrList = listUrl.Split(chrSplitter);
             if (arrList != null && arrList.Length > 0)
             {

                 using (SPSite site = new SPSite(listUrl))
                 {
                     using (SPWeb web = site.OpenWeb())
                     {
                         if(CheckListExists(SPEncode.UrlDecodeAsUrl(arrList[arrList.Length - 1]),web,ref objList))
                         {
                            //Add business logic here
                         }
                     }
                 }
             }
         

         }
         catch (Exception ex)
         {

         }
     }


Above function used to get data from SharePoint site by passing the url only. The url contain both site url and list name. For example:

From presentation layer, we make a call to GetListData function

string listUrl="http://chandanbadajena.blogspot.com/sites/mysite/Lists/ChandanKumarr";
GetListData(listUrl);

How to Use STSADM to Import/Export a SharePoint Subsite

The STSADM tool allows you to import and export SharePoint sites by specifying STSADM -0 Import and STSADM -o Export. The Import/Export options are ideal for backing up and restoring subwebs. To backup and restore entire site collections use STSADM -o Backup and STSADM -o Restore options.
Let’s say you want to backup a Demo subsite at http://www.server1.com/demos and restore it to a different site at http://www.server2.net/demos. You can use the following method to export the demo site and then restore it to the intended destination. If you want to preserve permissions use the -includeusersecurity switch.