Understanding Garbage Collection in Microsoft.NET

Garbage collection in Microsoft.NET is based on Mark and Compact algorithm and concept of generations.

 

Mark and Compact Algorithm

 

When an application is started a given amount of address space is allocated to the application which is called managed heap. We can make use of GetTotalMemory method of GC class to get the number of bytes currently allocated in managed memory. When a new object has to be instantiated and there isn’t enough space in the application’s managed heap, the garbage collection process runs.

 

  • Garbage collector generates a list of all the application’s objects that are still in scope.

 

  • The garbage collector steps through the managed heap, looking for any object that is not present in this list.

 

  • The garbage collector marks the objects that are out of scope. The space these objects were taking up is freed.

 

  • After the garbage collector has iterated through the managed heap, it moves the references to all the objects down to the beginning of the heap. All the object references are therefore stored contiguously in the heap.

 

 

Let’s take a simple example

 

Suppose when an application is started, objects A, B, C and D are instantiated, and references to these objects are placed on the managed heap.

 

Object D

Object C

Object B

Object A

 

Suppose later in the life of application, object E needs to be instantiated. Now there isn’t enough space in the managed heap so garbage collection needs to be performed. Objects B and C have gone out of scope.

 

When garbage collection is started, a list of all the objects that are still in scope is generated, here the list will contain object A and D, than it iterates through the managed heap, looking for the objects that are not present in the list. These objects are marked as unreachable and the managed heap is compacted. A reference to Object E is then placed on the heap.

 

 

Object D

Object C

Object B

Object A

 

To

 

 

Object E

Object D

Object A

 

 

 

Generations

 

Here in the above case it could be very expensive to step through the entire heap, looking for marked objects. To make this process more efficient, Microsoft.NET implements concept of generations. The theory of generations assumes that the older an object is, the less likely it is out to be out of scope during garbage collection. Therefore, it is most efficient to check the newest objects first and then check the older objects if space is still needed.

 

There are three generations: Generation 0, 1 and 2. When a garbage collection is performed, it collects only objects in Generation 0. If there is still not enough space to allocate a new object, then garbage collector moves on to Generation 1, and then if necessary, it moves to Generation 2 objects.

For e.g. consider an application that has object A in generation 2, B and C in generation 1 and D, E, F in Generation 0.

 

 

Object F

Gen 0

Object E

Gen 0

Object D

Gen 0

Object C

Gen 1

Object B

Gen 1

Object A

Gen 2

 

Now the application attempts to allocate space to Object G, but it cannot, so a garbage collection is required.

 

Say objects C, D and E have gone out of scope.

 

After the garbage collection, objects D and E are collected. Even though Object C had gone out of scope, the garbage collector only collected from Generation 0. If more space had been required than Object C, from Generation 1, would also have been collected.

 

And one more thing, the Object F will be moved to Generation 1 because it has survived one garbage collection. The garbage collector did not collect from Generation 1; therefore Object C is still within generation 1.

 

Now the managed heap would look something like this

 

 

 

Object G

Gen 0

Object F

Gen 1

Object C

Gen 1

Object B

Gen 1

Object A

Gen 2

  

 

Bye ..

Advertisements

Creating a custom Hello World web service in SharePoint

We need to do the following five steps

1) Create the web service.

2) Run disco.exe to get static disco and wsdl file for the web service.

3) Put asmx, disco and wsdl file to ISAPI folder.

4) Rename disco and wsdl file to aspx. Replace static url’s in them.

5) Add an entry to spdisco.aspx

Let’s proceed

· Create a new ASP.NET web service project.

· Rename Service.asmx to HWService.asmx.

· Right click it – select View Mark Up.

· And put the following mark up. Here we will be creating the web service with inline code.

<%@ WebService Language=”C#” Class=”MyInlineService.HelloWorldService” %>

using System.Web.Services;

namespace MyInlineService

{

public class HelloWorldService: WebService

{

[WebMethod]

public string HelloWorld()

{

return “Hello World”;

}

}

}

· Now Run Disco.exe for our HWService.asmx to create static disco and wsdl file.

· Open visual studio command prompt and run the following command

disco http://localhost:1814/HelloWorldSPService/HWService.asmx

· This will create HWService.wsdl and HWService.disco files at the current directory.

· Now copy all the three files HWService.asmx,HWService.wsdl and HWService.disco to ISAPI folder.

· Rename HWService.disco to HWServicedisco.aspx and HWService.wsdl to HWServicewsdl.aspx.

· Now we will open these new renamed wsdl and disco files to make the following modifications.

Open HWServicewsdl.aspx.

Replace

<?xml version=”1.0″ encoding=”utf-8″?>

with

<%@ Page Language=”C#” Inherits=”System.Web.UI.Page” %>

<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Import Namespace=”Microsoft.SharePoint.Utilities” %>

<%@ Import Namespace=”Microsoft.SharePoint” %>

<% Response.ContentType = “text/xml”; %>

And

<soap:address location=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; />

To

<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

Open HWServicedisco.aspx

Replace

<?xml version=”1.0″ encoding=”utf-8″?>

with

<%@ Page Language=”C#” Inherits=”System.Web.UI.Page” %>

<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Import Namespace=”Microsoft.SharePoint.Utilities” %>

<%@ Import Namespace=”Microsoft.SharePoint” %>

<% Response.ContentType = “text/xml”; %>

And

<contractRef ref=”http://localhost:1814/HelloWorldSPService/HWService.asmx?wsdl&#8221; docRef=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns=”http://schemas.xmlsoap.org/disco/scl/&#8221; />

<soap address=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns:q1=”http://tempuri.org/&#8221; binding=”q1:HelloWorldServiceSoap” xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

<soap address=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns:q2=”http://tempuri.org/&#8221; binding=”q2:HelloWorldServiceSoap12″ xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

with

<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + “?wsdl”),Response.Output); %>

docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns=”http://schemas.xmlsoap.org/disco/scl/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q1=”http://tempuri.org/&#8221; binding=”q1:HelloWorld” xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q2=”http://tempuri.org/&#8221; binding=”q2:ServiceSoap12″ xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

· Adding it’s entry in spdisco.aspx

Open the spdisco.aspx and add the following entry

<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx?wsdl”), Response.Output); %>

docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx”), Response.Output); %>

xmlns=” http://schemas.xmlsoap.org/disco/scl/ />

<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx?disco”),Response.Output); %>

xmlns=”http://schemas.xmlsoap.org/disco/&#8221; />

Now your web service should be availabe to be used within sharepoint context

http://servername:port/_vti_bin/HWService.asmx.

That’s it!!

Create a simple hello world custom Application Page in SharePoint.

There are two approaches we can follow while creating an Application Page in SharePoint.

One is Inline Approach

·         Create a new default.aspx page rename it to HelloWorldAppPage.aspx

·         Put the following markup in it

<%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master” Inherits=”Microsoft.SharePoint.WebControls.LayoutsPageBase” %>

<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>

  <asp:Label Text=”Hello World” runat=”server” ></asp:Label>

</asp:Content>

·         Every application page is an content page in SharePoint. And here to have same look and feel as the other application pages we have specified the application.master as the masterpagefile.

·         Inherits attribute of the Page directive refers to LayoutsPageBase class from which the application pages inherit.

·         We have than used a content server control that would be referring to the PlaceHolderMain content place holder inside the application.master page.

·         Than we have simple added a label control that would be displaying hello world.

·         Now go to your 12 hive i.e. C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS and create a folder (MyHelloWorld) over there and put the HelloWorldAppPage.aspx over there.

·         We could have directly placed the aspx page to layouts folder but than from better organization perspective we have created a folder and kept the aspx page inside it.

·         Now the page is available to all the SharePoint sites.

http://servername:port/_layouts/MyHelloWorld/HelloWorldAppPage.aspx

Another is code behind approach.

·         The easiest way is to first create a Asp.NET Web site project.

·         Add a class library project to the solution (GCL)

·         Delete class1.cs and copy the default.aspx.cs page from asp.net web site project to the class library project.

·         Delete the default.aspx.cs from the website.

·         Add reference to System.Web and Microsoft.SharePoint.dll  in your class library project

·         Put the following code in the _Default

public partial class _Default : LayoutsPageBase

{

    protected Label Label1;

    protected void Page_Load(object sender, EventArgs e)

    {

        Label1.Text = “Hello World Code Behind”;

 

    }

}

·         Sign the assembly and put it in GAC.

·         Get the public key token.

·         In the default.aspx page replace and put the following markup to use the assembly.

<%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master”

 Inherits=”_Default,GCL, Version=1.0.0.0,Culture=neutral,PublicKeyToken=16391a8a7c882343″ %>

<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>

  <asp:Label ID=”Label1″ Text=”Hello World” runat=”server” ></asp:Label>

</asp:Content>

·         Put default.aspx to the  layouts folder or your custom folder inside it.

That’ s it !!

Creating a Custom Web Service in SharePoint for Uploading Document

We had a requirement to upload the document to SharePoint document library whenever a file has been attached to our entities in Microsoft Dynamics CRM. So the obvious way of doing that was to use web service within the CRM. We had already written a utility using SharePoint Object Model that would be doing so. So we thought of reusing the existing logic defined over there and wrap it inside one our custom web service’s method. We created the web service and we deployed it in our SharePoint Server but outside the context of the SharePoint i.e. as a separate web site. However when trying to use that web service from other machines we ran into security issues, it was always giving Unauthorized Access error. We tried running the web service app pool with identity of administrator and also tried out impersonation defined through web.config again passing the account of administrator. But it didn’t work

Then finally tried out this article within MSDN which guides us on creating a web service that operates within the context of WSS 3.0.

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

Basic steps for creating a custom web service are following

1) Create a new asp.net web service project.

2) Add a new class library project in that solution.

3) Move Service1.cs file from web service project to class library project

4) Delete the Service1.cs file in web service project and class1.cs file in the class library project.

5) Put your custom logic in service.cs file that is now in the class library project.

6) Give strong name to the class library i.e. Sign the assembly.

7) Put the assembly in GAC. Get its public key token.

8) Now make modification to the service.asmx to use the assembly.

9) Replace code behind attribute with the class attribute to refer to the assembly

<%@ WebService Language=“C#” Class=“Service, MyServiceAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f2dca3c0f2d0131” %>

10) Generate static discovery and wsdl file.

11) Copy the .asmx file of the Web service to \Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS

12) From visual studio command prompt run the following command

disco http://MyServer:port/_layouts/MyCustomWebService.asmx

13) open both the .disco and .wsdl files and replace the opening XML processing instruction — <?xml version="1.0" encoding="utf-8"?> — with instructions such as the following

<%@ Page Language=“C#” Inherits=“System.Web.UI.Page” %>

<%@ Assembly Name=“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Import Namespace=“Microsoft.SharePoint.Utilities” %>

<%@ Import Namespace=“Microsoft.SharePoint” %>

<% Response.ContentType = “text/xml”; %>

14) In the .disco file, modify the contract reference and SOAP address tags

<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + “?wsdl”),Response.Output); %>

docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns=http://schemas.xmlsoap.org/disco/scl/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q1=http://tempuri.org/&#8221; binding=“q1:HelloWorld” xmlns=http://schemas.xmlsoap.org/disco/soap/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q2=http://tempuri.org/&#8221; binding=“q2:ServiceSoap12” xmlns=http://schemas.xmlsoap.org/disco/soap/&#8221; />

15) In the .wsdl file, make the following changes for the SOAP address

<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

16) Rename both files in the respective formats MyCustomWebServicedisco.aspx and MyCustomWebServicewsdl.aspx so that your service is discoverable through Windows SharePoint Services.

17) Copy the new MyCustomWebServicewsdl.aspx and MyCustomWebServicedisco.aspx files, and also the MyCustomWebService.asmx fil to _Drive:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPI directory

18) Open the spdisco.aspx files located in Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPI and add the following code, specifying the .asmx file for your Web service.

<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/MyCustomWebService.asmx?wsdl), Response.Output); %>

docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/MyCustomWebService.asmx), Response.Output); %>

xmlns=http://schemas.xmlsoap.org/disco/scl/ />

<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/MyCustomWebService.asmx?disco),Response.Output); %>

xmlns=http://schemas.xmlsoap.org/disco/&#8221; />

Any modification done to the custom logic would require putting the new assembly in GAC followed by generating the static disco and wsdl file and making all the necessary modification in disco and wsdl file as mentioned in the above steps.

Now in our case finally putting the custom logic of uploading the document within the class library for the web service helped us to solve the issues that we were facing.

[WebMethod]

public string UploadDocumentToSharePoint(string fileName, byte[] fileContents, string folderName)

{

if (fileContents == null)

{

return “Null Attachment”;

}

try

{

SPWeb web = SPContext.Current.Web;

web.AllowUnsafeUpdates = true;

SPFolder folder = web.GetFolder(folderName);

string fileURL = fileName;

folder.Files.Add(fileURL, fileContents);

return “File added successfully!”;

}

catch (System.Exception ex)

{

return “Error: “ + ex.Source + “| Message: “ + ex.Message;

}

}

And this is how we used it in within our custom application after adding the web reference to it.

FileStream oFileStream = File.OpenRead(@”C:g.doc”);

byte[] content = new byte[oFileStream.Length];

// store the contents in a byte array

oFileStream.Read(content, 0, (int)oFileStream.Length);

// close the stream

oFileStream.Close();

// instantiate the service

DocService.Service docService = new DocService.Service();

// pass the current logged in user credentials

docService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

// pass the name of the doc, content and document library name

string message = docService.UploadDocumentToSharePoint(“G1.doc”, content, “CrmDoc”);

MessageBox.Show(message);

Bye…

Deploying a web part in SharePoint.

We need to do the following to deploy the web part.

  • First we need to sign the assembly.
  • In Visual Studio right click project and select Properties.
  • In properties, select Signing Tab.
  • Select Sign the assembly check box.
  • And specify the file or create a new file.
  • Build the assembly.
  • Now the manual way of deploying the assembly would be to put it either in GAC or bin directory of the web application and put a safe control entry within the web.config of the web application.
  • However the preferred way of deploying is through a solution file, which would make our web part available in the solution management ( global configuration section) of Central administration page, from where we can deploy to multiple web applications.
  • For this we need to create a manifest file.
  • Right click the project.
  • Add New Item – Select an xml file – name it manifest.xml
  • Put the following code on the file

<?xml version=1.0 encoding=utf-8 ?>

<Solution xmlns=http://schemas.microsoft.com/sharepoint/

SolutionId=96A76C66-7258-4721-BEB4-90C06E656DB6>

                <Assemblies>

                                <Assembly DeploymentTarget=WebApplication

                                Location=DeploymentWebPart.dll>

                                                <SafeControls>

                                                                <SafeControl

                                                                Assembly=DeploymentWebPart, Version=1.0.0.0, Culture=neutral,

PublicKeyToken=b0d80600de0f4a2b

                                                                Namespace=DeploymentWebPart TypeName=*/>

                                                </SafeControls>

                                </Assembly>

                </Assemblies>

</Solution>

 

 

Soution ID – Create and assign a new guid.

DeploymentTarget attribute, which has two possible values: GlobalAssemblyCache or WebApplication.

 GlobalAssemblyCache indicates that the assembly should be deployed in the global assembly cache; WebApplication tells Windows SharePoint Services to drop the assembly in the private application folder of the IIS Web application

SafeControl element describes the configuration that must be done in the web.config file.

  • Now we will create the solution package, which is essentially a cabinet file that would contain our assembly and manifest file.
  • For this right click the project and select a CAB project from SetUp and Deployment projects folder.
  • Name it as DeploymentWebPartSolution
  • Right click the CAB Project and select – Add – Project Output.
  • In Project Output Group dialog box select the DeploymentWebPart and from the configuration drop down select Active.
  • In the project list box, select Primary Output to include the assembly.
  • Now again right click the cab project and select – Add – Project Output, this time select Content Files to include the manifest.xml.
  • Build the Project.
  • This will create DeploymentWebPartSolution.CAB file.
  • Rename it to DeploymentWebPartSolution.wsp
  • To add the solution package to solution store
  • Stsadm.exe -o addsolution -filename DeploymentWebPartSolution.wsp.
  • We now go to Solution Management link inside the Global Configuration section within Operations Tab of Central Administration Site.

There we will see our DeploymentWebPartSolution.wsp. Now click on it and select the web application where it should be deployed.

However if are creating our web part using web part project template within Visual studio 2008,  .wsp solution package automatically gets created for us when we select deploy command on right clicking the project. We can than make use of the .wsp file directly, no need to create a setup project in that case.

 

That’s it ….

 

Creating a Hello World Connectable Web Parts in SharePoint.

To write connectable web parts we need to do the following

First we need to define our own interface that will specify the data we want to pass from one web part to another.

The provider web part needs to do the following

  • Implement the interface.
  • Create a property which would be returning a reference to the interface.
  • The property should be decorated with ConnectionProvider attribute.

The consumer web part needs to do the following

  • It should contain the method which would receive the interface.
  • The method should be decorated with ConnectionConsumer attribute.

Keeping the above information in mind let’s start

 Create a new web part project within Visual Studio 2008. (HelloWorldConnectedWebPart)

Right click on the Project

Select Add New ItemàSharePointàWebPart.

Now rename the webpart1.cs and webpart2.cs class as  HWProviderWebPart and HWConsumerWebPart respectively.

Now right click the project and add a new interface class.

    public interface IStringData

    {

        string ProviderStringInfo { get; }

    }

Our Provider class should implement this interface and define one property which would be returning the reference to the interface.

[Guid(“56978c39-1958-4128-a979-b9feaf2feb46”)]

    public class HWProviderWebPart : WebPart, IStringData

    {

        public HWProviderWebPart()

        {

        }

        protected override void CreateChildControls()

        {                    

        }

        // the string info that would be passed to the consumer

        protected string myInfo = “Hello World”;    

        // implement the property defined in the interface

        public string ProviderStringInfo

        {

            get { return myInfo; }

        }     

        // create a property which would be returning the interface reference

        // decorate it with ConnectionProvider

        [ConnectionProvider(“String Provider”)]

        public IStringData ConnectionInterface()

        {

            return this;

        }

    }

 

Now let’s move to our Consumer Web Part.

[Guid(“3575c6de-e21a-4e5a-b7f0-fe1aa4844402”)]

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

    {

        public HWConsumerWebPart(){

        }

        protected override void CreateChildControls(){      

        }

 

        IStringData myProviderInterface = null;

        // The Consumer class should define a method that would accept

        // the interface as an parameter

        // Should be decorated with ConnectionConsumer attribute

 [ConnectionConsumer(“String Provider”)]

        public void GetInterface(IStringData providerInterface)

        {

            myProviderInterface = providerInterface;

        }

 

        protected override void Render(HtmlTextWriter writer)

        {

            try

            {  

                // priting the value provided by provider web part

                writer.Write(myProviderInterface.ProviderStringInfo);

            }

            catch(Exception ex)

            {

                writer.Write(“Error info “ + ex.Message);

            }

        }   

    }

 

Now build the project. ( Remove errors if any)

Right click the project.

Select Properties – Debug — Start browser with url ( Specify the site where the web part should be deployed)

Right click the project and select Deploy.

After Deploy Succeeds ,

Go to site actions — Site Settings — WebParts( Inside galleries) –Click on New– Select both the Provider and consumer web part — Populate Gallery.

Go to your home page —  Edit page — Add both the web parts –Select the provider web part — Connections and Specify the connection.

That’s it..

Understanding Web Part life cycle

Web Part Life Cycle starts with

OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part.

LoadViewState – The view state of the web part is populated over here.

CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.

OnLoad

User Generated Event – for e.g. button click on the web part.

OnPreRenderHere we can change any of the web part properties before the control output is

drawn.

RenderContents – Html Output is generated.

SaveViewState – View state of the web part is serialized and saved.

Dispose

UnLoad.

Bye…

Server Error in ‘/’ Application. Runtime Error on opening a SharePoint site

Got this error while opening a SharePoint site.

Changing custom error to Off it showed  the following error

Line 1:  <browsers>
Line 2:      <browser id="Safari2" parentID="Safari1Plus">
Line 3:          <controlAdapters>

Data at the root level is invalid. Line 1, position 1.

Deleted  the _vti_cnf folder of /App_Browsers/ of the site and everything was back to normal!!!

Difference between workflow created using SharePoint Designer and Visual Studio Designer for Windows Workflow Foundation.

SharePoint Designer

Visual Studio 2005 Designer for Windows Workflow Foundation.

 

Can write only sequential workflows.

Can write both sequential and state machine workflows.

 

Automatic deployment against the specific list or library against which workflow is being designed.

Can be deployed as a feature.

Logic is defined declaratively using Steps which comprises of Conditions and Actions

Logic could be defined through custom code written using C# or VB.NET.

Workflows could be associated to a specific list or library.

Workflow can be authored as Template which once deployed could be associated with any list or library.

Workflow modifications not possible.

Workflow modifications are possible using Modification forms built using ASP.NET or InfoPath form.

Workflow markup, rules all are stored as a document library on the site.

Workflows are compiled as an .NET assembly.

Can’t be debugged.

Debugging is possible using Visual Studio.

Using Workflow Object Model in SharePoint.

I was assigned a task to create a simple aspx page where the user could see all the all the different documents, workflows running against them, workflows task information as well as workflow history.

Here we can make use of SPWorkflow and SPWorkflowTask class.

The page would be displaying the information in the following manner

Workflow status for following document :-SampleDocument1
Workflow name :- Approval Workflow
Workflow Task Title
First Team Task
Second Team Task
Third Team Task
Workflow History Description
The approval workflow has started waiting for and Second Team to respond
Task has been created and assigned to First and Second Team
First and Second team has completed their task

Workflow status for following document :- SampleDocument2
Workflow name :- Approval Workflow
Workflow Task Title
First Team Task
Workflow History Description
The approval workflow has started waiting for First and Second Team to respond

The sample code for getting the above information

protected void Page_Load(object sender, EventArgs e)

{

//SPWorkflowManager myWFMgr = new SPWorkflowManager();

SPSite objSite = new SPSite(http://servername:port&#8221;);

SPWeb objWeb = objSite.OpenWeb();

SPList myList = objWeb.Lists[“ListName”];

// for each document within the Library

foreach (SPListItem myListItem in myList.Items)

{

Response.Write(“<b>Workflow status for following document :-</b>” + myListItem[“Title”].ToString());

Response.Write(“</br>”);

// Get the workflows associated

foreach (SPWorkflow myWF in myListItem.Workflows)

{

// Get the name of the workflow

Response.Write(“Workflow name :- “+ myWF.ParentAssociation.Name);

Response.Write(“</br>”);

Response.Write(“<b>Workflow Task Title </b>”);

Response.Write(“</br>”);

// for each workflow running get the workflow tasks and history information

foreach (SPWorkflowTask myWFTask in myWF.Tasks)

{

Response.Write(myWFTask[“Title”].ToString());

Response.Write(“</br>”);

}

// for each workflow running get the history information

Response.Write(“<b>Workflow History Description</b> “);

Response.Write(“</br>”);

SPList myList1 = objWeb.Lists[“Workflow History”];

SPQuery query = new SPQuery();

query.Query = “<OrderBy><FieldRef Name=”ID”/></OrderBy>” +

“<Where><Eq><FieldRef Name=”WorkflowInstance”/>” +

“<Value Type=”Text”>{“ + myWF.InstanceId.ToString() + “}</Value>” +

“</Eq></Where>”;

SPListItemCollection historyListItems = myList1.GetItems(query);

foreach (SPListItem i in historyListItems)

{

Response.Write( i[“Description”].ToString());

Response.Write(“</br>”);

}

}

Response.Write(“</br>”);

}

}

That’s it …