The Unsatisfied

Blog

view:  full / summary

Started my own site finalllyyyyy :D:D:D:D

Posted by Mad on November 4, 2010 at 11:59 AM Comments comments (0)

started my site finally...

currently blogging on it

http://sharepoint.madhurchadha.com


Sharepoint Blog,tips and tricks,FAST ESP

here ill talk about all things sharepoint from wss 3.0 to MOSS to Sharepoint2010 to even FAST ESP

Started a parallel blog

Posted by Mad on July 20, 2009 at 4:48 PM Comments comments (1)

started a parallel blog on blogspot specifically for sharepoint...

m really fedup with ads shown in thi site...still not sre if i should go about and keep it

have a look at this

 

http://madsharepoint.blogspot.com/

 

Creating a List Instanca through a feature

Posted by Mad on January 18, 2009 at 12:28 AM Comments comments (0)

A very neat way to create a list instance is through a feature.

For eg you have list definition with a feature ID

you need to create another feature suppose list instance

in this feaature folder you will have an instance.xml whi will contain information likee

1. name of the list instance you want to create

2. listtemplate feature ID

 

now as soon as this feature is activated on any web a list with the name you specified and of the type you selected would be automatically created

 

get SPWeb from URL by passing it to SPSite constructor

Posted by Mad on December 18, 2008 at 12:19 AM Comments comments (0)

Saw this  strange behaviour of SpSite.openweb(). the web object depends on tne URL passed as parameter for spsite

 

for eg if you want to get an spweb object from a URL  do the following

 

SPSite site = new spsite(<complete path upto the web level>);

SPWeb web= site.OpenWeb();

 

now this will give you not the spweb object of the root web but the one whose url is passed in spsite constructor.

Neat :) 

Ajax enabled webpart

Posted by Mad on November 19, 2008 at 6:07 AM Comments comments (0)
Ajax Enabled Webpart using user controls in Sharepoint
Wednesday, Nov 19, 2008


Introduction

 

For creating an Ajax enabled webpart we first need to install Ajax extensions, configure web.config to support Ajax,and also add script manager to the master page. For steps refer to the following link

http://msdn.microsoft.com/en-us/library/bb861898.aspx

 

You will additionally need to add a Script Manager in  the master page. You Can alternatively  add it in the webpart also

Adding Script Manager:

In master page file add the ScriptManager tag under the webpartmanager tag like this

   <WebPartPages:SPWebPartManager ID="SPWebPartManager1" runat="server"/>

    <asp:ScriptManager id="SM1" runat="server">

Now we will be creating user control and adding that as a child control in  web Part.  It will have two parts

Creating a User Control

1.       Create a new ASP.net website.

2.       Add a new item ?Web User Control?  to the project

3.       If you had installed Ajax extensions ,in toolbox you will see Ajax extensions heading

4.       Drag UpdatePanel control on the user control.

All controls inside update panel do an asynchronous postback. They update themselves without submitting the entire page.

Now we will add controls in the update panel

5.       Drag a button and a label inside update panel

6.       On button click we will set label text to current date time

 

Note: Here the UpdatePanel will get updated whenever any button inside it is clicked. We can alternatively use selective updates by using the concept of triggers. Triggers can be defined in the ascx file itself so that the UpdatePanel updates itself only on click of these controls

 

Eg

 

<asp:UpdatePanel ID="WebPartUpdatePanel" runat="server">

 

    <ContentTemplate>

 

Update Panel Content/controls are kept here

 

    </ContentTemplate>

 

    <Triggers>

 

        <asp:AsyncPostBackTrigger ControlID="btUpdatePanel" EventName="Click" />

 

    </Triggers>

 

</asp:UpdatePanel>

 

 

Here a button btUpdatePanel is the trigger and on click event of this button, asynchronous postback takes place

 

 

7.       In Usercontrol code behind write the code to update the label text with current date time

8.       Copy the ascx file and .cs file into the following location on each front end server

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

 

Note: Here we have copied both ascx file and cs file into the control template. This is only for the development purposes .In development environment you would like to add the user control codebehind in the webpart project and inherit the user control from this class

 

Eg:

 

<%@ Control Language="C#" AutoEventWireup="true" Inherits="MyFirstUserControl,MyFirstWebpart,Version=1.0.0.0,Culture=neutral,PublicKeyToken=4a122e291d325327" %>

 

Here MyFirstUserControl is the name of the user control class and MyFirstWebpart Is the name of the webpart Dll which now contains the user control class also

 

Creating a Webpart

1.       Now we need to create a webpart project

2.       We now add the user control as a child control of the webpart.

 

Sample code is given below

using System;

 

using System.Runtime.InteropServices;

 

using System.Web.UI;

 

using System.Web.UI.WebControls;

 

using System.Web.UI.WebControls.WebParts;

 

using System.Xml.Serialization;

 

 

using Microsoft.SharePoint;

 

using Microsoft.SharePoint.WebControls;

 

using Microsoft.SharePoint.WebPartPages;

 

 

namespace MyFirstAjaxwebpart

 

{

 

    [Guid("9af2a5db-6122-4a80-8d2a-8842e7d0e084")]

 

    public class MyFirstAjaxwebpart : System.Web.UI.WebControls.WebParts.WebPart

 

    {

 

        public MyFirstAjaxwebpart()

 

        {

 

            this.ExportMode = WebPartExportMode.All;

 

        }

 

 

        protected override void CreateChildControls()

 

        {

 

            base.CreateChildControls();

 

            EnsurePanelFix();

 

 

            UserControl ajaxControl = new UserControl();

 

            ajaxControl = (UserControl)(UserControl)this.Page.LoadControl(@"/_controltemplates/" + "AjaxWebPartUserControl.ascx");

 

            this.Controls.Add(ajaxControl);

 

       

 

        }

 

        private void EnsurePanelFix()

 

        {

 

            if (this.Page.Form != null)

 

            {

 

                String fixupScript = @"

 

     _spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");

 

     function _initFormActionAjax()

 

     {

 

       if (_spEscapedFormAction == document.forms[0].action)

 

       {

 

         document.forms[0]._initialAction =

 

         document.forms[0].action;

 

       }

 

     }

 

     var RestoreToOriginalFormActionCore =

 

       RestoreToOriginalFormAction;

 

     RestoreToOriginalFormAction = function()

 

     {

 

       if (_spOriginalFormAction != null)

 

       {

 

         RestoreToOriginalFormActionCore();

 

         document.forms[0]._initialAction =

 

         document.forms[0].action;

 

       }

 

     }";

 

                ScriptManager.RegisterStartupScript(this,

 

                  typeof(MyFirstAjaxwebpart), "UpdatePanelFixup",

 

                  fixupScript, true);

 

            }

 

        }

 

 

    }

 

}

 

 

Note: MOSS before SP1 did not officially support AJAX. EnsurePanelFix is used to use update panel control in webparts.

 

Also note that if you are using the above given ensurepanel update, only one webpart on a page should contain this else you might get stack overflow errors.

 

 

For more information have a look at this link

 

http://support.microsoft.com/kb/941955/en-us

 

3.       For Deploying the webpart we will set the path shown as below

4.       You will also need to add a reference to system.web.extensions

5.       Deploy the webpart by right clicking on the project and choosing deploy

Note: Here we are directly deploying the project on the server using the visual studio template. For development environments you will need to copy the feature folder in feature folder of 12 hive,put the dll in GAC,add a safe control entry  and run stsadm command to install and deploy the feature

6.       Now the webpart will be available in the webpart gallery of that site. We add the webpart on the required page

7.       On clicking on the button the label text is updated with the current text without refreshing the page

 

Since no page refresh takes place, for time consuming processes the user might get confused if his request has been submitted or not. To avoid this problem we can show an update progress bar which will be visible when an asynchronous update is happening.

Adding an Update Progress

1.       Drag the update progress control on the user control.

 

2.       Set the Update Progress properties as follows

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">

 

<ProgressTemplate>

 

 <img src="\_layouts\images\ajaxupdate.gif" />

 

</ProgressTemplate>

 

</asp:UpdateProgress>

 

Here we have set the associate update panel Id so that the progress indicator is shown only if Update Panel 1 is updating. If we do not specify this then any ajax updates happenings will active it.

This scenario is useful when we have multiple updatepanels on a page and we wnt to show a common update indicator for all.

Also we have set the progress template. This is nothing but the progress indicator . We specify an image kept in images folder under 12 hive as the template.

 

Complete demo  user control code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AjaxWebPartUserControl.ascx.cs" Inherits="AjaxWebPartUserControl" %>

 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

 

    <ContentTemplate>

 

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

 

        <asp:Label ID="Label1" runat="server" Text="Label" Width="78px"></asp:Label>

 

    </ContentTemplate>

 

</asp:UpdatePanel>

 

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">

 

<ProgressTemplate>

 

 <img src="\_layouts\images\ajaxupdate.gif" />

 

</ProgressTemplate>

 

</asp:UpdateProgress>

 

 

Now whenever ajax update takes place the image is visible as shown below

 

This was a small sample of Ajax enabled webparts in MOSS. We can extend the functionalities of these webparts by using various controls like ModalPopup extender etc available in ajaxcontrol toolkit.

These will be discussed in detail in the next Bok

References

1.       MSDN

Create a custom workflow in MOSS using Visual studio

Posted by Mad on November 18, 2008 at 10:30 AM Comments comments (1)

A quick refrence manual for creating a custom workflo using infopath and connect it with infopath task form

1.       Crete a new project of type SharePoint server sequential workflow

2.       Double click on Workflow1.cs file to see the designer

3.       Drag activity Create task and end task activity

4.       Create Task Property setting:

a.       Correlation token: create a new one eg task1

b.      Owner activity: Workflow1 (taken from drop down)

c.       Task Id: Bind to a new memberàcreate a new field

d.      TaskProperties: Bind to a new memberàcreate a new field

5.       Complete task property settings

a.       CorrelationToken: same as create task

b.      TaskId: same as create task

e.      TaskProperties:  Bind to a new memberàcreate a new field

6.       Double click on create task activity to create its method

7.       Double click on complete task activity to create its method

8.       Create task method coding:

//here createTask1_TakId1 is the new field created in step 4 subsection c

//TaskType defines which infopath  will be used with this task as task form

createTask1_TaskId1 = Guid.NewGuid();

createTask1_TaskProperties1.TaskType = 0;

you may specify other properties like

createTask1_TaskProperties1.Title = "new title";

createTask1_TaskProperties1.AssignedTo =/;

9.       Design a new infopath form

10.   Infopath settings

a.       Go to toolsàform options

b.      Under security and trust category select domain level

c.       Under Compatibility make sure ? design a form template that can be opened with browser or InfoPath ?is checked

11.   Publishing the form:

a.       Publish to a network location fileàpublish

b.      Publish in FeatureFiles folder in your solution folder

c.       No public URL should be set URL should not be used

d.      Click next

e.      Click publish

12.   Workflow.xml settings

a.       In workflow.xml  right click and select insert snippet sharepoint serveràworkflow.xml

If snippets are not visible you need to add it refer to this linkà

b.      Fill in the GUID (get a new GUID from toolsàcreate GUID  ,use registry  format only and do remove the curly braces around it)

c.  Delete

 AssociationUrl="_layouts/CstWrkflIP.aspx"

         InstantiationUrl="_layouts/IniWrkflIP.aspx"

         ModificationUrl="_layouts/ModWrkflIP.aspx"

StatusUrl="_layouts/WrkStat.aspx"

? after StatusUrl

Also delete

<Modification_GUID_FormURNmodificationURNModification_GUID_FormURN

<Modification_GUID_NameName of ModificationModification_GUID_Name

<AssociateOnActivationfalseAssociateOnActivation

These will be used if we are using association form ,instantiation for etc etc.see MOSS sdk for example

d.      Replace ProjectName with name of your project file

e.      Replace taskFormURN with the Urn of the task form . To get this open the published infopath form in design more(right clickàdesign) and go to file properties

f.        Fill in the public key token of the dll .To do this sign the aseembly and put the dll in GAC ,right click in gacàproperties)

g.       Change the workflow title and description

13.   Feature.xml settings

a.  Insert feature.xml code the same way we did for workflow.xml

b.  Delete <ElementFile Location="MyForm.xsn"

c.  Fill in a new GUID

d.  You can change the title,description etc

14.   PostBuildActions.bat configurations

a.       Change http://localhost to the url of the site on wish to deploy this workflow

Linking My Site Back to Portal sitein MOSS

Posted by Mad on September 26, 2008 at 10:27 AM Comments comments (0)

Linking My sites Back to the portal site in MOSS

 To view the document with screenshots click here

In sharepoint MY SITES are hosted on a different web application. If a person is on any portal site and clicks on MY SITE link there is no back link to the homepage. The only way a person can come back is using back button of the browser or simply typing the URL

. In Moss each page has a link to My Site ie if multiple sites/portal sites are hosted on the same server ,each of them would have the My Site link by default and if they are under the same SSP then they will point to the same My Site location

                                                                                               

Now  a back link to the portal homepage in MY SITES is commonly a requirement for various customers

There are various ways to achieve this functionality:

a.       Edit the master page  to include a link to main portal this way  all the newly build my sites  will have a back link: Not recommended because there are easier way around

b.      Add a personalization site links: Adds a Tab between My Site and My Profile : Easy and applies to all new and existing sites. But does not look very good

c.       Portal site link: Adds a breadcrumb: Looks good ,easy to implement but applies only to newly created my sites.

In this article I will deal with methods 2 and 3

A.     Add a personalization site link

1.       Go to shared service administration page

2.       Click on Personalization site links under User Profiles and My sites

3.       Click on New  to add a new link

4.       Fill in the required details and click OK

5.       You may use multiple links and use target audiencing to show the correct link for eg if there are multiple site collections for different departments like Finance,HR,RnD then you may add links for each site collections homepage and use target audiencing to display the correct link.The finance person shall see a link to finance sites homepage ,HR to HR Sites homepage etc

6.       Now this link will be visible as a tab between My Home and My Profile on My Site

Note: This tab might not be visible immediately. Wait for a few minutes to see the tab

Now the problem with this method is that if I click on the training portal tab that I just added on MY Site, the portal  opens in My site view. The global navigation still remains of My Site. Both My Home and My Profile are still visible

                                                                                                             

The work around: There is a very neat workaround for this. We can create a redirect page that redirects to your portal home page . In Personalization site link we can give the path of this redirect page instead of the portal page

To create a redirect page simple put this code in a notepad and save as html

<html>

<META HTTP-EQUIV="Refresh" content= "0;URL=<Your Portal URL>">

</html>

Now upload this HTML on the  MOSS server and use this URL

B.  Portal Site Link:

There is a very nice way of including your portal url in the bread crumb of you?re MY SITES.

This method is applicable to other site collections as well

Suppose you?re my Sites are  at this location

http://<servername>:portno/personal/<MySite>

1.       Go to this URL: http://<server name>:<port no>/_layouts/settings.aspx

2.       Go to Portal Site Connection Under site collection administration

3.       Select Connect to Portal Check Box and fill in Portal URL and Portal name

4.       Click OK

That?s it. Now all the newly created My sites will have the Portal Home page in the bread crumb

 

References : http://mphacker.spaces.live.com/blog/cns!8040CC624DDC5404!214.entry

                        Office sharepoint server Administrative Companion

/show/448129-

Posted by Mad on September 26, 2008 at 10:13 AM Comments comments (0)

Basic event handling in MOSS

Posted by Mad on August 26, 2008 at 10:28 AM Comments comments (1)

 


 

Let me start with what is event handling.

Definition of event handling ?an event handler is an asynchronous callback subroutine that handles inputs received in a program?

Confused?? Ok in simple language event handling is doing some stuff when some predefined stuff happens. Example theft happens àpolice starts investigation.

Now here eventàtheft happens

Event handleràPolice(keeps a watch)

Event handler functionàInvestigation starts

Event handling is software is also the  same . In MOSS various events happen like adding a new item, deleting an item, creating a site,deleting a site etc

Now if we want to do some stuff whenever these events happen we need an event handler. Like if there is a theft an investigation can start only if there is a police officer

Now what are the types of crimes errr types of events an event handler can handle? Some event receiver base classes are listed below

Base Receiver

Events

SPWebEventReceiver

SiteDeleted

SiteDeleting

WebDeleted

WebDeleting

WebMoved

WebMoving

Base Receiver

Events

SPListEventReceiver

FieldAdded

FieldAdding

FieldDeleted

FieldDeleting

FieldUpdated

FieldUpdating

SPItemEventReceiver

ItemAdded

ItemAdding

ItemAttachmentAdded

ItemAttachmentAdding

ItemAttachmentDeleted

ItemAttachmentDeleting

ItemCheckedIn

ItemCheckedOut

ItemCheckingIn

ItemCheckingOut

ItemDeleted

ItemDeleting

ItemFileConverted

ItemFileMoved

ItemFileMoving

ItemUncheckedOut

ItemUncheckingOut

ItemUpdated

ItemUpdating

You need to write your custom code using these base classes for creating an event handler.

Now lets start and create our first event handler. Note this is not a hello world event handlers so you won?t see any hello world popping on your screen .The event handler that we will create will simply copy a newly added list item?s title into another list as simple as that.

1.    Go t visual studio and create a new class library project

2.    Give it any name you wish to(No restriction of MY_First_Event_handler J)

3.    Now delete the default class

4.    Add a reference to Microsoft.SharePoint.dll(May be visible with the name windows sharepoint services)

5.    Create a new class and inherit it from SPItemEventReceiver class

6.    Now since we need to trigger it on item added override the ItemAdded method(its like we tell the policeman what action to take when a murder happens)

7.    Argument for this function is SPItemEventProperties properties . this variable properties can be used to access the properties of an event like itemname, itemId,Web name,site name etc(its like initial FIR who was murdered,where did the murder took place etc etc)

8.    Using this write your custom code. See the code snippet below

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

namespace __madhur_ClassLibrary1_event

{

class ApplicationEventReceiver : SPItemEventReceiver

{

public override void ItemAdded(SPItemEventProperties properties)

{

SPWeb web = properties.OpenWeb();

SPList list = web.Lists["Events"];

SPListItem item = list.Items.Add();

list.Update();

item["Title"] = properties.ListItem.Title;

item.Update();

web.Close();

}

}

}

9.    Next step is to sign your assembly ,compile it and put I into GAC(global assembly cache)

10. Now we have told the policeman what he needs to do when a murder happens. But should he start his investigation whenever a murder happens, anywhere? I mean should a policeman in Punjab start investigating when someone is murdered in Honolulu .No, we need to assign him an area. Like you will investigate only if something happens in suppose sector 6,7,8 Chandigarh .Similarly we need to add our event handler to some list/library.So that it fires only when an item is added to that list

11. To do this we need to write a console application.See the code sample below

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

namespace EventReceiverRegister

{

class Program

{

static void Main(string[] args)

{

SPSite site = new SPSite("");

SPWeb web = site.OpenWeb("");

//list to which the event receibver is attached

SPList list = web.Lists[


Rss_feed