Friday, November 7, 2008

SharePoint Master Pages Components Overview

Master Pages

A single master page file can control the look and feel of countless pages within a site/application. It is basically a next generation approach of how to include common content in lieu of frames or server side include files.

Content Pages
Master pages store the layout and design, while content pages define the content. The content page is bound to a master page. Together the two create the presentation layer of content for a site/application.
In SharePoint content pages are called Page Layouts. But they work similar to content pages. The master page file is combined with the page layout to create the presentation layer of content for the SharePoint site. Master Page and Page Layout combine to create the rendered page






The Components of a SharePoint Master Page File


The master page will contain all of the user interface layout code for the site. This includes CSS, JavaScript and HTML.

Examples of what you would put in the master page:
• Header code including company logo and branding images
• Navigation
• Footer code including copyright statements and links
• CSS (cascading style sheet) styles
• Body background colors, images or styles
• Common JavaScript functions

SharePoint 2007 Backup Schedule in Windows 2008

There is no feature available in Microsoft SharePoint 2007 Central adminisration to schedule the back up/restore operations.
The best method is to create a batch file, write the stsadm command for taking and storing backup on some floder of your server or netwrok folder, and finaly put that on windows task scheduler.

Open 'Notepad'

Type Following and save as "SharepointBackschedule.bat"


@echo off
echo =============================
echo Back up sites for the Server farm to C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SharePoint\

echo =============================

@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"

cd C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SharePoint\

@echo off

md "%DATE:/=_%"

echo ========================================

echo Directory based on the current date daytime created

echo ========================================

%STSADM% -o backup -directory "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SharePoint\%DATE:/=_%" -backupmethod full -overwrite

echo completed


Now Click on













Click on Trigger, click on New and select the schedule (Daily/Weekly etc)

Click on the Action and click on new and browse the batch file you have created.

Click Ok

And your scheduler is ready.













Wednesday, November 5, 2008

How to use JS in Sharepoint Masterpages

Save you js file under 12 hive on the following location of the sharepoint server

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033

Add the reference In your master page

Determine If Windows SharePoint Services Is in Active Directory Account Creation Mode

To determine if you are in Active Directory account creation mode, type the following command at a command prompt, and then press ENTER:

stsadm.exe -o getproperty -pn createadaccounts
• A response of indicates that Windows SharePoint Services is in Active Directory account creation mode.

• A response of indicates that Windows SharePoint Services is not in Active Directory account creation mode.

SharePoint: Add, deploy, Delete solution

For adding and deploying solution

C:\cd C:\Program Files\Common Files\Microsoft Shared\Web Server Ex
tensions\12\BIN

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN>stsa
dm -o addsolution -filename /.wsp

Go back in central admin, deploy the solution

Deleting Solution

from central admin, operations, solutions, Retract the solution
from command line run: stsadm -o deletesolution -name
e.g.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN>stsa
dm -o deletesolution -name abc.wsp

Install Feature Command

stsadm -o installfeature -filename SubmissionList\feature.xml -force
stsadm -o activatefeature -filename SubmissionList\feature.xml -url http://localhost
iisreset

Create User in SQL server 2005

CREATE LOGIN [mdi_user] WITH PASSWORD=N'mdi_user', DEFAULT_DATABASE=[IDT_DEV], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

SharePoint : Add group of users to the user collection programmatically

SPWeb web = new SPSite("Site URL").OpenWeb();
SPUserInfo[] userInfo = new SPUserInfo[1];
userInfo[0].Email = "email@microsoft.com";
userInfo[0].LoginName = @"domain\username";
userInfo[0].Name = "username";
userInfo[0].Notes = "Test";
web.Roles["Reader"].Users.AddCollection(userInfo);

Code

1. using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
namespace AddUsers
{
class AddUserClass
{
static void Main(string[] args)
{
SPSite siteCollection = new SPSite(”Site URL”);
SPWeb site = siteCollection.OpenWeb();
SPGroup AddUserGroup = site.Groups["Group Name"];
AddUserGroup.AddUser(”domain/alias”, “email address”, “Name”, “Description”);
OR
SPRoleAssignment MyRoleAssign = new SPRoleAssignment(”domain/alias”, “email address”, “Name”, “Description”);
SPRoleDefinition MyRoleDef = newSubWeb.RoleDefinitions["Contribute"];
MyRoleAssign.RoleDefinitionBindings.Add(MyRoleDef);
site.RoleAssignments.Add(MyRoleAssign);
site.Dispose();
siteCollection.Dispose();
}
}
}

Thursday, October 23, 2008

Custom Columns, Custom List and Content type creation and installation

There are several steps involved in creating a custom list definition in SharePoint 2007. These are:
1. Create custom site columns (Optional)
2. Create custom content types (Optional)
3. Create custom list definition

The trick is to make sure that the list definition is based on a content type that contains all the site columns required in the list definition (or the columns will not show up in the ‘add new item’ form).
So the first two steps can be avoided if your list definition is based on existing site columns and content types.

The following example will create a custom ‘TechComment’ list definition that could be used for accepting Technical Comments on a particular technical issue.
To do this a custom site column that will hold the Technical comments is created.
This and several existing site columns are used to create a custom ‘TechComment’ content type. The TechComment list definition is then created based on this content type.
Each item is deployed as a separate feature in this example.

Creating a custom site column for the TechComment comments

1. Create a folder named TechCommentColumns in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES (FEATURES) directory.

2. Create an xml file named feature.xml inside this folder that contains the following information:
http://schemas.microsoft.com/sharepoint/">

3. Create a xml file named TechCommentcolumn.xml that contains the following information:http://schemas.microsoft.com/sharepoint/"> http://schemas.microsoft.com/sharepoint/v3" StaticName="TechComments" Group="Technical Comment Columns" Type="Note" DisplayName="Comments" Sortable="FALSE" Description="Comments on the Tech issue" Sealed="TRUE" UnlimitedLengthInDocumentLibrary="TRUE" AllowDeletion="TRUE" ShowInFileDlg="FALSE">

Here we are defining the system name (Name and StaticName) the base type (Type) and several other attributes of our site column.
The FEATURES\fields folder contains examples of default site columns, and is useful in understanding how all these attributes are used.

4. Activate the feature using the following commands
(in a command window, from the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN directory):stsadm -o installfeature -filename TechCommentColumns\feature.xml -force

stsadm -o activatefeature -filename TechCommentColumns\feature.xml -url http://localhost/

Creating a custom ‘TechComment’ content type

1. Create a folder named TechCommentCT in the FEATURES directory.

2. Create a xml file named feature.xml that contains the following information:

http://schemas.microsoft.com/sharepoint/">

3. Create a xml file named TechCommentct.xml that contains the following information:http://schemas.microsoft.com/sharepoint/"> Here we are defining basic attributes for our content type and the site columns that we will be using. One important piece of information is the ID attribute. This tells us that our content type is based on the content type with ID 0x01, the ‘Item’ content type.
The FEATURES\ctypes folder can be used to find the ID’s of system content types we might want to use as a base.
You should also check that the ID of your new content type is unique.

Another important point to note is that the FieldRef ID's must match ID's for existing site columns.
We can see that the ID of the TechCommentComment field matches that of the site column we defined in step 1 by looking at the elements xml file we used to define the column.

To find out the ID of other fields we want to use you can look in the FEATURES\fields folder to see a list of all the default field/column types.

4. Activate the feature using the following commands:

stsadm -o installfeature -filename TechCommentCT\feature.xml -forcestsadm -o

activatefeature -filename TechCommentCT\feature.xml -url http://localhost/

Creating a custom TechComment list definition

1. Create a folder named TechCommentsList in the FEATURES directory.
2. Create a xml file named feature.xml that contains the following

information:http://schemas.microsoft.com/sharepoint/">

3. Create a folder named ListTemplate inside the TechCommentsList folder and add an xml file named TechComments.xml that contains the following

information:http://schemas.microsoft.com/sharepoint/"> Here we are defining a unique type number for our list (which can be used if we want to include this list in a custom site definition), the sequence it should appear in the ‘create’ page and other basic attributes. Note the displayname used must match the folder that contains the list schema defined in the next step.

4. Create a folder named TechComments inside the TechCommentsList folder and copy the FEATURES\CustomList\CustList\Schema.xml file into the TechComments folder.

5. Update the ContentTypes element in the Schema.xml file to the following:
Here we define our custom ‘TechComment’ content type as the base type for this list.The columns defined in this content type are then shown on the ‘add new item’ page.

6. Update the Fields element in the Schema.xml file to the following: http://schemas.microsoft.com/sharepoint/v3" StaticName="Title"> http://schemas.microsoft.com/sharepoint/v3" StaticName="FullName"> http://schemas.microsoft.com/sharepoint/v3" StaticName="Email"> http://schemas.microsoft.com/sharepoint/v3" StaticName="TechCommentComments" Group="TechComment Columns" Type="Note" DisplayName="Comments" Sortable="FALSE" Description="Comments on the TechComment" Sealed="TRUE" UnlimitedLengthInDocumentLibrary="TRUE" AllowDeletion="TRUE" ShowInFileDlg="FALSE"> Here we define the custom fields from our content type that we want to use in our list.

7. Lastly update the ViewFields element to contain the columns we want to display on our default list view:

8. Activate the feature using the following commands:stsadm -o installfeature -filename TechCommentList\feature.xml -forcestsadm -o activatefeature -filename

TechCommentList\feature.xml -url http://localhost/iisreset

You should now be able to create a new instance of the TechComments list from the create list page as shown below:
Some points to note are that the ID's for features and fields you create need to have new GUID's generated for them. When including fields in content types or list definitions the GUID/ID must match the GUID of the list (you can look in the feature folder for the field to find this out).

Wednesday, May 28, 2008

The first Application Template for Windows SharePoint Services 3.0 now available

Resolution related to ApplicationTemplateCore.wsp command line error:
Finally what helped to us is as following:
1)Download the solution .EXE file to your computer.
2)Run the .EXE file to unpack the template file
to a location on your computer.
Copy ApplicationTemplateCore.wsp file in to
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN location
3)Click on Start
4)Click on Run
5)Type Cmd
6)Type CD C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
7)Type(Don't paste, that would not work)following command
STSADM.EXE -o addsolution -filename ApplicationTemplateCore.wsp

Enjoy!
psharma.net@gmail.com

SharePoint End User Security

Very Nice article on Authentication.
http://blogs.msdn.com/arpans/archive/2008/05/09/sharepoint-end-user-security.aspx?CommentPosted=true#commentmessage

Tuesday, May 27, 2008

Adding user control to SharePoint 2007 (MOSS/WSS) Web Part

1. Open Visul Studio 2008/2005, Add New Project> Select Empty Template name "Test.Development"

2. Add a Webpart by selcting the Webpart template Name "TestUCWebpart "

a. Create a object of User Control

UserControl _control;

b. Add following code in public class

this.ExportMode = WebPartExportMode.All;

c. Add following code in Create child control
_control = (UserControl)Page.LoadControl(@"~/_controltemplates/Mycompany/UC.ascx");
Controls.Add(_control);

d. Add following code in Render
base.RenderContents(writer);


Following is the code
*****************************WebPart code***************************************

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 Test.Development{
[Guid("4154895c-4160-4db5-adf2-849d9848a97f")]

public class TestUCWebpart : System.Web.UI.WebControls.WebParts.WebPart
{

UserControl _control;


public TestUCWebpart()
{
this.ExportMode = WebPartExportMode.All;
}

protected override void CreateChildControls() {
_control = (UserControl)Page.LoadControl(@"~/_controltemplates/Mycompany/UC.ascx"); Controls.Add(_control);
}

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

******************************End of Webpart code**************************************


3. Add New project as ASP.NET Webapplication Name "UCWebApplication"

a. Add One Web control (.ascx) "UC.ascx"

b. Write Code desing and code

c. Add following on the top in .ascx file

//Webpart Assembly name
//Modify ascx
//Register

4. Assign Strong Key

5. Build

Following is the code

***************.ascx***********************












FL
CA
GA
TN
KY



Label1...........







**************end of ascx*******************

***************.cs***********************

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace UCWebApplication
{
public partial class UCNew : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string szState = ddlState.SelectedValue;
lblResults.Text= "Hello" + txtFirstName.Text + txtLastName.Text + txtCity.Text + szState ;

}

protected void btnReset_Click(object sender, EventArgs e)
{
lblResults.Text= "Hello" ;
txtCity.Text = "";
txtFirstName.Text = "";
txtLastName.Text = "";
ddlState.SelectedIndex = 0;
}
}

}
*************end of .cs*******************


6. Copy AScx and ascx.cs in to controltemplates//

7. copy .dll of control webapplication to C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin

8. Go to C:\Inetpub\wwwroot\wss\VirtualDirectories\80 and edit Web.config

9. Add both the assemblies in to safecontrol list



10. Add both the assemblies in asseiblies list
a.
b.

11. Make Trust

12. Webpart is ready now