Monday, March 21, 2011

Error:Share Point Timer Service Not Activated

Hi all, i got an exception like "service timer not started......." while activating a web part feature to a site in share point. In share point all the operations run on a service timer, That's why i am not able to move single inch forward from that state. After googling for some time i got the solution. I am providing the screen shots here how to rectify the issue.


run the services.msc to check the services activated.


select the windows share point service timer. It is not started.So try to start it. If it started, your issue solved. Otherwise it is giving any error check the properties as shown below.


You will get the window as shown below.


Check the radio button is on local System Account or not. If it is not to the local system out then make it as local system account.

Now it will work fine.

Get The Input values from web part editor part in share point 2007

In SharePoint Portal Server 2003, which called its reusable widgets WebParts. Thus, it makes perfect sense that ASP.NET 2.0 provides fantastic support for WebParts, and it definitely is no surprise to see Microsoft Office SharePoint Server 2007 (MOSS 2007) built upon this very framework. This article discusses WebPart framework basics, which can serve as the foundation for more advanced topics such as WebPart support in MOSS 2007.

The Major Components of the ASP.NET 2.0 WebPart Framework
Before diving into a sample WebPart-driven Web site, you must first understand the major reusable controls built into the .NET framework, which you will use to set up the site:


  1. WebPart: A WebPart is a reusable widget on a Web page. The user can choose to add a WebPart on his page, customize the WebPart per his needs, or even define communication between various WebParts. An ASP.NET 2.0 WebPart inherits from the System.Web.UI.WebControls.WebParts.WebPart class. A good example is a widget that displays traffic. End-user customization could involve specifying a freeway, and communication with another WebPart could involve a different WebPart that has a list of freeways that the user can click, one by one, to view updated traffic information. Setting up something like that is not very difficult in ASP.NET 2.0.
  2. WebPartManager: This control is the central policeman of the ASP.NET 2.0 WebPart framework. Each page should contain only a single WebPartManager, which is responsible for managing all functionality, events, and customization of various WebParts on that page. WebPartManager also has the ability to set various modes. So, for instance, if the user sets the WebPartManager in a Catalog mode, he could pick and choose the WebParts he wants on his page from a catalog of WebParts. Alternatively, he could put the page in Communication mode and define the various connections between different WebParts.
  3. Various Zones: Zones are physical areas on a page. These are implemented in the following Server Controls that ship with the Framework:

  • WebPartZone: A WebPartZone is a control that defines an area on a page where one or more WebParts can be hosted. A WebPartZone also controls the look and feel of a WebPart inside itself. Also, any control that doesn't inherit from the WebPart class can masquerade itself as a WebPart and live inside a WebPartZone. This is done with the help of the GenericWebPart class, which inherits from the WebPart base class. By doing so, you are restricted to a subset of the functionality that a WebPart class can expose.
  • CatalogZone: The CatalogZone is the menu or the catalog from which a user can choose. It holds a number of CatalogPart controls, which in turn hold WebParts that are already added to the site and ready for the picking to add to various pages on the site. The user can pick WebParts from the Catalog, and add them to the various WebPartZones on the same page.                                         There are three types of CatalogParts: DeclarativeCatalogPart, PageCatalogPart, and ImportCatalogPart.
  • EditorZone: This is the area on the page that prompts the user to edit his WebPart and customize it to his specific needs. A WebPart can also be customized in a Shared mode, where an administrator can configure the WebPart and all other users can view or use the WebPart but not customize it.
  • ConnectionsZone: This is the area of the page that prompts the end user to define communication between various WebParts on the same page. For instance, you could build an online RSS reader. One WebPart holds the user's OPML, and the other WebPart renders the RSS for a particular subscription. The connection between the two would be the OPML WebPart providing a row (the RSS URL) and the RSS reader WebPart consuming the row, and then rendering appropriately. Because this is a simple ASP.NET 2.0 Web site, you can wrap these inside an atlas:UpdatePanel or a third-party control such as the telerik AJAX Panel. You even can eliminate postbacks and replace them with AJAX callbacks with almost no code at all.





Below code shows how get input from web part editor of a SharePoint page. Here i am taking the drop down list in the web part editor page and a label to display the selected value in the drop down list. We will get the all the lists of the site to the drop down list by using the code, and the selected list value to the label in the web part.


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Collections;

namespace WebPartEditPart
{
    [Guid("0f0072e7-6735-45b5-b8b6-1ed9c54e39e9")]
    public class WebPartEditPart :WebPart
    {
        private string text = null;
        private Label lblmessage;

        //[Personalizable(PersonalizationScope.Shared)]
        //[WebBrowsable(true)]
        //[System.ComponentModel.Category("My Property Group")]
        //[WebDisplayName("MyProperty")]
        //[WebDescription("Meaningless Property")]
        public string Text
        {
            get { return text;}
            set {text = value; }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            lblmessage = new Label();
            lblmessage.Text = this.Text;
            Controls.Add(lblmessage);
        }

        public override EditorPartCollection CreateEditorParts()
        {
            TextDisplayEditorPart textDisplayWebpart = new TextDisplayEditorPart();
            textDisplayWebpart.ID = this.ID + "editorPart";

            ArrayList editorArray = new ArrayList();
            editorArray.Add(textDisplayWebpart);
            return new EditorPartCollection(base.CreateEditorParts(), editorArray);
        }

        private class TextDisplayEditorPart : EditorPart
        {
            private DropDownList ddlList;

            protected override void CreateChildControls()
            {
                base.CreateChildControls();

                SPWeb currentWeb = SPContext.Current.Web;
                SPListCollection listCollection = currentWeb.Lists;
                if (listCollection.Count != 0)
                {
                    ddlList = new DropDownList();
                    ddlList.DataSource = listCollection;
                    ddlList.DataTextField = "Title";
                    ddlList.DataValueField = "Title";
                    ddlList.DataBind();
                    Controls.Add(ddlList);
                }
            }

            protected override void RenderContents(HtmlTextWriter writer)
            {
                base.RenderContents(writer);
                //ddlList.RenderControl(writer);
            }

            public override bool ApplyChanges()
            {
                EnsureChildControls();
                if (!string.IsNullOrEmpty(ddlList.SelectedItem.Text))
                {
                    WebPartEditPart webpart =(WebPartEditPart)WebPartToEdit;
                    webpart.text = ddlList.SelectedItem.Text;

                    return true;
                }
                return false;                
            }

            public override void SyncChanges()
            {
                EnsureChildControls();
                WebPartEditPart webpart =(WebPartEditPart)WebPartToEdit;
                if (string.IsNullOrEmpty(ddlList.SelectedItem.Text))
                {
                    ddlList.SelectedItem.Text = webpart.text;
                }
            }
            // Access the drop-down control through a property.
        }
    }
}

In the above code text is the property to get the input from web part editor. CreateChildControls() method to initialize the controls in the web part.ApplyChanges() method is used for get the input.SyncChanges() method is keep the selected value in the webpart editor.
deploy add activate the feature in the share-point site. That's it. You are done with it.

here is the final image

Add Fields to list in share point through coding.

In share point lists we have the fields. We can add the fields to list though administration. Here is the code to add the fields to list through coding.
        /// Add a field to the list
        private static void AddFieldToList(SPList list)
        {
            string fieldName = string.Empty;
            Console.WriteLine("enter the name of the field to add");
            fieldName = Console.ReadLine();
            if (!string.IsNullOrEmpty(fieldName))
            {
                if (list.Fields[fieldName] == null)
                {
                    list.Fields.Add(fieldName, SPFieldType.Text, true);
                    list.Update();
                    Console.WriteLine("New field added to " + list.Title);
                }
                else
                {
                    Console.WriteLine("field already exists in"+list.Title);
                }
            }
            else
            {
                Console.WriteLine("field name should not be null or empty");
            }           
        }
This is pretty straight way, may help you.