Wednesday, 25 July 2012

What is a Solution Package?

What is a Solution Package?

A solution is a deployable, reusable package that can contain a set of Features, site definitions, and assemblies that apply to sites, and that you can enable or disable individually. You can use the solution file to deploy the contents of a Web Part package, including assemblies, class resources, .dwp files, and other package components. A solution file has a .wsp file extension.
How to add the solution to the sharepoint farm and then deploy it to a particular web application is discussed below.

1. Adding solution package to the server

stsadm.exe -o addsolution -filename myEventCalendarList.wsp
OR
Use the complete location of the file, for example:
stsadm.exe -o addsolution -filename “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\Solution\myEventCalendarList.wsp”
Deploy solution package
Deploy solution package command

2. Deploying the Solution

Deploy the solution using the following command:
stsadm -o deploysolution -name myEventCalendarList.wsp  -url http://sp-dev/ -local  -force
Here( -url) means the web application where to deploy the solution.
OR
Goto, Central Administration > System Settings >Manage farm solutions
Now click your solution from the list (for example, myEventCalendarList.wsp).
Manage farm solutions
Manage farm solutions
a)  Now click Deploy Solution and select the web application where you want to deploy the solution (example, http://sp-dev here), Click OK when you are done.
select the web application
Click Deploy Solution
Select web application
Select web application where you want to deploy
b)  And finally you will have your solution deployed status like the following.
solution deployment status
solution deployment status
You are done with deployment.

Export DataTable to Excel in MOSS 2010 and Asp.Net without using excel interop




private void ExportToExcel(DataTable dt, string fileName, string worksheetName)
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename="+ fileName + "");
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
            DataGrid dataExportExcel = new DataGrid();
            dataExportExcel.ItemDataBound += new DataGridItemEventHandler(dataExportExcel_ItemDataBound);
            dataExportExcel.DataSource = dt;
            dataExportExcel.DataBind();
            dataExportExcel.RenderControl(htmlWrite);
            StringBuilder sbResponseString = new StringBuilder();
            sbResponseString.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40/"> <head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>"+ worksheetName +"</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
            sbResponseString.Append(stringWriter + "</body></html>");
            Response.Write(sbResponseString.ToString());
            Response.End();
        }
        void dataExportExcel_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                //Header Text Format can be done as follows
                e.Item.Font.Bold = true;
                //Adding Filter/Sorting functionality for the Excel
                int cellIndex = 0;
                while (cellIndex < e.Item.Cells.Count)
                {
                    e.Item.Cells[cellIndex].Attributes.Add("x:autofilter", "all");
                    e.Item.Cells[cellIndex].Width = 200;
                    e.Item.Cells[cellIndex].HorizontalAlign = HorizontalAlign.Center;
                    cellIndex++;
                }
            }
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                int cellIndex = 0;
                while (cellIndex < e.Item.Cells.Count)
                {
                    //Any Cell specific formatting should be done here
                    e.Item.Cells[cellIndex].HorizontalAlign = HorizontalAlign.Left;
                    cellIndex++;
                }
            }
        }

Wednesday, 18 July 2012

Adding Paging in SPGridview

Many times we need to create custom SpGridview control and need to add paging in such control,Here I have gone through bit of code which facilitate to add paging in SPGridview Control.

SPGridView gv = new SPGridView();
gv.AutoGenerateColumns = false;
gv.AllowPaging = true;
gv.PageSize = 10;
gv.PageIndexChanging += new GridViewPageEventHandler(gv_PageIndexChanging);

gv.PagerTemplate = null; //You must add this line before binding the DataSource.
gv.DataSource = dv;//Here dv is an object of Dataview
gv.DataBind();

Now you need to add PageIndexChanging Event.

void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv.PageIndex = e.NewPageIndex;
gv.DataBind();
}

How to change language of an existing SharePoint site collection

Hi All,
Recently I had problem with SharePoint site. The problem was that the site was created in “English” and I want to change the language from ‘English’ to ‘Dutch’. Once site Collection has been created with any language, I was not able to change the language with existing site collection.
After doing some research I found solution.
Resolution:
The language of the site is stored at SP Web level. It is stored in database in Webs table. So you need to change the language in database whatever language you want. To change the language in database you need to fire following Query:

For changing the language of all sites in to ‘Dutch’ language:
UPDATE dbo.Webs SET Language = 1043

Changing the language of one site collection: (Dutch language)
UPDATE dbo.Webs SET Language = 1043 WHERE SiteId = [[SiteCollectionId]]

Changing the language of a single web or subsite: (Dutch language)
UPDATE dbo.Webs SET Language = 1043 WHERE Id = [[WebId]]

Note:
Before applying the new language, you need to verify that the language pack for the language that you want to apply is installed on your machine or not. If language pack is not installed then follows the below steps:

1. Go to link:
http://www.microsoft.com/downloads/details.aspx?FamilyID=2447426b-8689-4768-bff0-cbb511599a45&displaylang=en
2. Change the language for what you want to install the pack. Click on Download.
3. SharePoint Products and Technologies Configuration Wizard will open after installing language pack. On the completing the SharePoint Products and Technologies Configuration Wizard, click Next.
4. On the Configuration Successful page, click Finish.
5. The new language’s folder is available at ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template’. (I.e. for English it would be ‘1033’, for Dutch it would be ‘1043’).

After installing language pack, you can apply different language with SharePoint site.
Hopefully it will helpful to you.

Tuesday, 17 July 2012

How to Check Workflow Status programmatically

How to Check Workflow Status programmatically
Today I'll show checking all workflow statuses in SharePoint site programmatically. Sometimes you may want to check workflow statuses are error or not.







You need workflow status name (list column) when you get a item's workflow status. But you can't get workflow status name from SPWorkflow properties directly. You need to use SPWorkflow.AssociationId property and SPList.WorkflowAssociations property to get workflow status.


using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

// This is Console Application //

SPSite site = new SPSite("http://sharepoint-site");
SPWeb web = site.OpenWeb();

foreach (SPList list in web.Lists)
{
foreach (SPListItem item in list.Items)
{
foreach (SPWorkflow workflow in item.Workflows)
{
try
{
Console.WriteLine("item url : " + item.Url);
Console.WriteLine("workflow name : " + list.WorkflowAssociations[workflow.AssociationId].Name);
Console.WriteLine("workflow status : " + item[list.WorkflowAssociations[workflow.AssociationId].Name]);
Console.WriteLine();
}
catch (ArgumentException)
{
//ArgumentException is throwed if the workflow is not exist in the list column.
Console.WriteLine("Workflow name : {0} is already not exist in List title : {1}.",
list.WorkflowAssociations[workflow.AssociationId].Name, list.Title);
}
}
}
}