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).