Monday, July 23, 2007

My notes on MOSS 2007

This notes is created to give training for my juniors on basic overview on sharepoint .



What is portal

Portal is a web application that gathers information from various desperate sources to share the information among the users .

The portals has the following significant features
· collabaration
· security
· personalization
· customization
· search , etc

Site which are not portals are called vertical portal or Vortals

Windows share point services 3.0 is free licensing it has less feature compare to Moss 2007


Ghost able – stored in content database

Un ghost able – stored in hard disk


Web part

Web part is a custom control , created by a developer and deployed on to the share point site with the extension dwp or webpart(recommended) .

Web part zone

Web part zone is a logical area created by the designer on a web part page where the web part can be dropped.

Web part page

Page, which contain web parts.

There are two type of deployment

· stand alone Installation (Deployment ) – Everything is there in the same system .
· web form Installation ( Web garden) -
A Web garden is an application pool that is configured with more than one worker process. (Web gardens are to be distinguished from Web farms, which use multiple servers for a Web site.)






Hierarchy
Central administration


site administrator


Top-level sites

Top level site 1 - Top level site 2

Role

Administrator – can create sites, content, users, application, manage forms.

Designer – can create manage content and design of the website

Contributor – can only contribute to existing content .

Reader – no other permission except view.


Feature

Feature are new innovation in Moss 2007 these are plug gable component which actually modifies the structure, layout programming capability of share point site .


Sample code which display a simple html web part page

using System.Configuration ;
using Microsoft.SharePoint .WebPartPages ;
using Microsoft.SharePoint;


namespace tpg.SFO
{
public class SFO : WebPart
{
#region Controls Initialization
protected Literal litContent = new Literal();
protected Label lblMessage = new Label();
protected Panel pnlHtml = new Panel();
public string currentURL = string.Empty;
//private tpg.ConfigurationReader.Configurations configReader = new tpg.ConfigurationReader.Configurations();
//Load the xslt file from the specified location
Configurations config = new Configurations();
tpg.CustomMessages.CustomMessages custommessage = new tpg.CustomMessages.CustomMessages();
#endregion

protected override void RenderWebPart(System.Web.UI.HtmlTextWriter writer)
{
base.RenderWebPart(writer);
}
///
/// Create Input controls which is needed to capture the data
///

protected override void CreateChildControls()
{

litContent.Text = "";
SPWeb web = SPContext.Current.Web ;
currentURL = web.Url ;


litContent.Text = CreateHtmlContent();
this.pnlHtml.Controls.Add(litContent);
this.Controls.Add(pnlHtml);

}



///
/// Build a HTML file which display a static page
///

public string CreateHtmlContent()
{
string htmlContent = string.Empty ;
try
{
// some html Content ;

}
catch (Exception ex)
{
ShowMessage(custommessage.getMessage("general_error"));
}
return htmlContent;

}
///
/// get redirect location from config
///

private string getUrl(string info)
{
string url = string.Empty;
SPWeb web = SPContext.Current.Web;
currentURL = web.Url;
string configValue = string.Empty;
try
{
configValue = config.getConfigurationValue(info, "value");
}
catch { }
configValue = configValue + "?CId=" + info + "&AId=302 ";
url = currentURL + configValue;
return url;


}
///
/// get redirect location from config
///

private string getImagepath()
{
string imagePath = string.Empty;
imagePath = config.getConfigurationValue("pentagon", "value");
return imagePath;

}



///

///
/// This is to show normal messages.
///

///
private void ShowMessage(string message)
{
lblMessage.Text = message;
lblMessage.CssClass = "error";
this.Controls.Add(lblMessage);
}

}
}





Additional notes


Microsoft Office SharePoint Portal Server 2003 (the current release) is a Web Portal which belongs to the Microsoft Office family. It is a collaborative portal application based on the Windows SharePoint Services platform, a free component of Windows Server 2003. Windows SharePoint Services offers online publishing of standard file formats. It also has version control, document approval and a basic search facility

Microsoft Office SharePoint Server 2007, commonly abbreviated to MOSS, is the successor to Microsoft Office SharePoint Portal Server 2003. It has a large range of new features not in the previous version.
MOSS is a licensed enterprise extension to version 3.0 of the no-cost Windows SharePoint Services platform - a component available for Windows Server 2003. Its main strength is enabling an organization’s information to be organized and aggregated in one central, web-based application. It can be configured to return separate content for Intranet, Extranet and Internet locations. The primary areas of investment that Microsoft has made over the previous version are Excel Services, Infopath Forms Services, the Business Data Catalog, Enterprise Search, web content management, more specialized document management, records management, web 2.0 collaboration functionality like blogs and wikis, delivery of information stored in SharePoint via RSS, PowerPoint Slide Libraries, and the ability to take content and lists offline with Outlook 2007 and Microsoft Access.

One of the weaknesses of the tool is its own ease of use. Administrators may be tempted to start one port 80 and build a single site collection with sub-sites underneath, exposed to the company as a home page and sub-pages. Though this makes logical sense for a large organization or one with bespoke portals using custom Web Parts or Forms Server, it can cause problems. All the sites in a site collection will be stored in the same database, which can become too large to effectively back-up. Moreover, bespoke development using the same Web Application and Application pool can bring a company-wide internet down.

When designing a large implementation it makes sense to break distinct areas of the organization in to their own portal with their own Web Applications.
MOSS 2007 also allows content types and document libraries to have information management policies, which allows the triggering of workflow or deletion after a certain fixed event or time period, helping to reduce many of the size-growth problems of earlier versions.

Monday, July 16, 2007

pagination in datagrid webpart in sharepoint

The Best way to bind datagrid with the Pagination property and Edit and update command .


I was stuck in Adding pagination property to datagrid which was created under sharepoint webparts .

The Next pagination is working but Prev Pagination is not working. I tryed with somany ways but not able to find out .

Atlast I rearranged the code which handle viewstate properly ..

This is the code which works properly ...

public class TestHOF : WebPart
{

// To get the data from databse
public static DataSet getData()
{
DataSet ds = new DataSet();

return ds;
}
//======================================================================
///
/// Method to get connection string from web.config
///

//======================================================================
public static string GetConnectionstring()
{
string connStr = string.Empty;
try
{
connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
}
catch
{


}

return connStr;
}

private MyDataGrid grid;

private bool DynamicColumnsAdded
{
get
{
object o = ViewState["DynamicColumnsAdded"];
if (o != null)
{
return (bool)o;
}
return false;
}
set
{
ViewState["DynamicColumnsAdded"] = value;
}
}

protected override void CreateChildControls()
{
grid = new MyDataGrid();
grid.ID = "DataGridInsideWebPart";
grid.AllowPaging = true;
grid.PageSize = 5;
grid.PagerStyle.Mode = PagerMode.NextPrev;
grid.PagerStyle.NextPageText = "Next";
grid.PagerStyle.PrevPageText = "Prev";
grid.ItemCommand += new DataGridCommandEventHandler(this.LanguageGrid_ItemCommand);
grid.UpdateCommand += new DataGridCommandEventHandler(this.LanguageGrid_UpdateCommand);
grid.PageIndexChanged += new DataGridPageChangedEventHandler(grid_PageIndexChanged);
grid.AutoGenerateColumns = false;

this.Controls.Add(grid);
ChildControlsCreated = true;
}

void grid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
grid.CurrentPageIndex = e.NewPageIndex;
grid.DataSource = getHOFMembersData();
grid.DataBind();
}

protected override void OnLoad(EventArgs e)
{
EnsureChildControls();
if (!DynamicColumnsAdded)
{
AddColumns();
}
if (!Page.IsPostBack)
{
grid.DataSource = getData() ;
grid.DataBind();
}
base.OnLoad(e);

}

public void LanguageGrid_ItemCommand(Object sender, DataGridCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
Page.Response.Write("Edit:" + e.Item.ItemIndex);
this.LanguageGrid_EditItem(sender, e);
}
if (e.CommandName == "Update")
{
Page.Response.Write("Update:" + e.Item.ItemIndex);
this.LanguageGrid_UpdateCommand(sender, e);
}
}

public void LanguageGrid_EditItem(Object sender, DataGridCommandEventArgs e)
{
grid.EditItemIndex = e.Item.ItemIndex;
grid.DataBind(); // Refreshes the grid
}

public void LanguageGrid_UpdateCommand(Object sender, DataGridCommandEventArgs e)
{
string language = e.Item.Cells[0].Text;
grid.EditItemIndex = -1;
grid.DataBind();
}

protected override void LoadViewState(object savedState)
{
EnsureChildControls();
object[] stateArr = (object[])savedState;
base.LoadViewState(stateArr[0]);
grid.LoadDGViewState(stateArr[1]);
if (DynamicColumnsAdded)
{
AddColumns();
}
}

protected override object SaveViewState()
{
object[] state = new object[2];
state[0] = base.SaveViewState();
state[1] = grid.SaveDGViewState();
return state;
}

private void AddColumns()
{
BoundColumn languages = new BoundColumn();
languages.DataField = "CategoryId";
languages.HeaderText = "CategoryId";

EditCommandColumn edit = new EditCommandColumn();
edit.ButtonType = ButtonColumnType.LinkButton;
edit.EditText = "Edit";
edit.UpdateText = "Update";
grid.Columns.Add(languages);
grid.Columns.Add(edit);

DynamicColumnsAdded = true;
}

private class MyDataGrid : DataGrid
{
public void LoadDGViewState(object state)
{
this.LoadViewState(state);
}

public object SaveDGViewState()
{
return this.SaveViewState();
}
}






}

Thursday, July 12, 2007

WebService in Sharepoint

One of the majour part which I have worked in my project is connecting webpart and web service.

May be this article will give a an Idea of how we can Add a asmx page into sharepoint
and also how to use the existing web service in Share point .


1) Create an ASP.NET Web service in Microsoft Visual Studio 2005.
Create a class library within the Web service that defines the programming logic for the Web service.


Create a strong name for the class library:
add your assembly to the global assembly cache (GAC),
Open TestFiles.asmx page Remove the CodeBehind attribute and Add the class
<%@ WebService Language="C#" Class="Files,clsUploadService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c741d2e07f0e3abc" %>


where "Files" represents the class name that you provide in Files.cs and " clsUploadService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c741d2e07f0e3abc" is the one which we get from Reflector.exe ( this procedure is similar to the process of getting assembly name )

2) Generate and edit a static discovery file and a Web Services Description Language (WSDL) file.
To provide discovery and description for your custom Web service, you must create a .disco file and a .wsdl file
In Windows Explorer, copy the TestFiles.asmx file of your Web service to \\ Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS.
Disco.exe at the command promp ( from Microsoft tools - command) disco http: // mytestwebsite:4704 / _layouts/TestFiles.asmx
( mytestwebsite:4704 is the server name ) after this open the wsdl and disco files with this link
http://mytestwebsite:4704/_layouts/TestFiles.asmx?disco
http://mytestwebsite:4704/_layouts/TestFiles.asmx?wsdl
save both file as aspx files TestFilesdisco.aspx and TestFilesWSDL.aspx
In both file replace 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"; %>



3) replaces literal paths with code generated paths
in disco file
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns="http://schemas.xmlsoap.org/disco/scl/" />

xmlns:q1="http://tempuri.org/" binding="q1:HelloWorld" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

in WSDL file
/>


4) Copying the Web Service Files to the _vti_bin Directory
The _vti_bin virtual directory maps physically to the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI directory, which contains the default Web service files used in Windows SharePoint Services. Copy the new MyCustomWebServicewsdl.aspx and MyCustomWebServicedisco.aspx files, and also the MyCustomWebService.asmx file, to the ISAPI folder.
To verify navigate to http://mytestwebsite:4704/_vti_bin/TestFiles.asmx.

5 ) Add the New Web Service in spdisco.aspx

To make your Web service discoverable in Visual Studio as a Web service alongside the default Windows SharePoint Services Web services, open the spdisco.aspx file located in \Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI and add the following code, specifying the .asmx file for your Web service.

docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/ TestFiles.asmx"), Response.Output); %>
xmlns=" http://schemas.xmlsoap.org/disco/scl/ " />

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

To create web part which connects to WebService ( TestWebpartServices ) and returns data
add a web reference to http://mytestwebsite:4704/_vti_bin/TestFiles.asmx. and name that has mytestwebsite
public class TestWebpartServices : WebPart
{
private mytestwebsite.Files file = new global::TestWebpartServices.mytestwebsite.Files();
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{

file.PreAuthenticate = true;
file.Credentials = CredentialCache.DefaultCredentials;
writer.Write(file.HelloWorld());
}
}
and after this create web Part from this dll and Import this in application you can see a message "Hello World" .

when I was creating web service application in 2005 we dont have any option to edit the proxy class .i.e reference.cs file will not create .. but if we do this with the class project we can see reference.cs file




MOSS 2007 Training

Microsoft® Office SharePoint® Server 2007

I got a chance to undergo training on MOSS 2007 , since our client Palladiume USA wanted to shift to sharepoint portal .

The Training was conducted by Mr Gurjit , It was about 1 week .

Windows SharePoint Services is a versatile technology included in Microsoft Windows Server 2003 that enables organizations and business units of all sizes to increase the efficiency of business processes and improve team productivity.