Friday, February 27, 2009

Customize /_layouts files in Sharepoint 2007

Customizing PlaceHolder values in MOSS 2007
Here something
intresting while changing some text based in the _layouts/ folder.These folders
pages cannot be customised in Share point designer.
Case 1:
In a wiki site we need to chagne the CreatewebPage.aspx
label "New Wiki Page " to "My Library page."

A quick solution would be
to, remove the line the bwlow Sharepoint Tag :

<SharePoint:EncodedLiteral runat="server"
text="<%$Resources:wss,webpagecreation_newwk_pagetitle%>"<%$Resources:wss,webpagecreation_newwk_pagetitle%>
EncodeMethod='HtmlEncode'/ >

And replace it with:
<SharePoint:EncodedLiteral runat=”server”text=” Text I want” EncodeMethod=’HtmlEncode’/>

Though this would work, this is not recommended.My friend (Pawan) gave me an idea to do these change in resource file.

________________________________________________________________

Case 2:
A customer of mine wanted to get rid of the “Error: Access Denied” message that’s displayed to unauthorized (but authenticated) users in MOSS 2007/WSS V2. Instead, user wanted something like “Feel free to join this site”, which according to her organization would convey a more positive message to users.

I had a look at the AccessDenied.aspx page and as expected couldn’t find the text in question. Instead, there were content placeholders. This page uses the “simple.master” as its master page. Certain content placeholder IDs are overridden here. A few are “PlaceHolderPageTitle”, “PlaceHolderPageTitleInTitleArea”, “PlaceHolderMain” and the likes.
A quick solution would be to, remove the line:

<SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,accessDenied_pagetitle% >” EncodeMethod=’HtmlEncode’ &gt
And replace it with:
< SharePoint:EncodedLiteral runat=”server” text=”whatever text I want” EncodeMethod=’HtmlEncode’ >
Though this would work, this is not recommended.

________________________________________________________________

Recommended Solution

Another way is to understand how resources work and try tampering with it (well, a copy of it actually).The overridden attribute is referencing a resource file.You would see something like:
<%$Resources:wss,accessDenied_pagetitle%>
or
< %$Resources:wss,webpagecreation_newwk_pagetitle%>
The above syntax indicates that we need to look into wss resource file located *somewhere* and need to find the variable “accessDenied_pagetitle” or "webpagecreation_newwk_pagetitle".
Under \12\config\resources and the others under \app_globalresources folder of the individual virtual directories created by MOSS 2007/WSS v2.
Modifying the wss.en-US.resx file under \12\config\resources wouldn’t reflect the change in the UI.
This would also mean we are modifying the default OOB files and is not recommended.
We can modify the wss.en-US.resx file under \app_globalresources and that would reflect the changes.
Note:Every time a new web application is create the resource files are copied over to \app_globalresources and they govern the resource part of that application.Pop open the wss.en-US.resx under \app_globalresources file and look for the variable “accessDenied_pagetitle” or "webpagecreation_newwk_pagetitle" in it. There would be a data name/value pair. You’ll also see wss.resx file. If you have a wss.en-US.resx (the en-US part can vary depending on the language), you'll need to use that. If you don't, you can use wss.resx.But, if both wss.resx and wss.en-US.resx (or any other language file) are present, wss.en-US.resx would take precedence.

Thursday, February 26, 2009

Customize Search - Advanced Search.

This article will explain how to customize MOss2007 Search - Advanced Search page
Add a newly created column in Property Restriction dropdown to customize advanced search.
1. Log in to your SSP site and go into search settings. Go into "Content sources and crawl schedules" and do a full crawl to make sure Share Point’s search knows about your column. We need to do the full crawling after a new column gets added in document library to make is proper indexing.
2. Now go to the search settings and go to "Metadata property mappings" and click on "New managed property". On this page give a unique name to your managed property, choose a data type for it, and map it to one or more "Crawled Properties" by using the "Add Mapping" button down the bottom. Search for your column and click add. Once your done do another full crawl to re-index the metadata as a managed property.




Content type is already defined in managed property in Moss as shown in below screen shot.




3. Now you need to customize the advanced search page to tell it when to allow people to use your new property. Browse to your advanced search page, and under the site actions menu select "edit page". In the "Advanced Search Box" web part, use the edit menu and select "Modify Shared Web Part". In the right hand pane expand the properties category, and look for the Properties XML option. This contains XML that tells Share Point how to display the advanced search. You need to add the following to this XML:



4. Under the node, add a tag like this
Where ="{Managed Property Name} equals the name of the managed property that you created in the SSP, {Data Type} matches the data type you gave the property in the SSP, and {Display Name} is what you want the property to appear as in the drop down menu on the advanced search page





5.In one (or all if you want to) of the nodes add the following node: This will have your property appearing in the drop down for each result type you add it for (by default in result types you have all results, word documents, excel document and presentations, if you want it to appear for all of these searches (and other custom ones) you need to add this tag to each ResultType tag).



In this way a new property can be added in advanced search page property restrictions dropdown.
Result page
Result page after adding a new property Content type in Property restriction dropdown looks like.









































Tuesday, February 24, 2009

Upgrate SPS2003 Team site TO MOss2007

1 Pre-Upgrade Steps
Verify that WSS 2.0 Service Pack 2 is installed Install .NET Framework 3.0 Enable Microsoft ASP.NET 2.0 in IIS Web Service Extensions Communicate downtime to site owners and users
2 Upgrade Steps The upgrade steps are explained below:


2.1 Run the Prescan.exe
Copy the “Prescan.exe” from your local drive Run the prescan tool from a command prompt with the following parameter (Prescan.exe /all) Browse the prescan log and lookout for errors. Errors occur if there are orphaned sites/ subsites or lists. These errors should be corrected either by fixing them or if not found to be active, they can be removed. (Refer to section 2.4 below for fixing errors)


2.2 Install WSS 3.0 Run the setup exe for WSS 3.0 Select Gradual Migration in a upgrade tab Select Web Front End in a server tab and click next Cancel the Configuration Setting Wizard (Don’t the config wizard). Install WSS 3.0 SP1 Uncheck the Configuration Setting Checkbox and Close the Wizard.


2.3 Create the Site Definition Folder as described in my previous article


2.5 Create the Upgrade file Copy an past the upgrade.xml file and past from the below path C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG\UPGRADE and replce its content with WSS to the new site definition name[XYZ].


2.6 Run the configuration Wizard Select "No, I want to create a new server farm” Provide database Server Name, Database name, User Account Info Hit Upgrade You should get Configuration Status as Successfully Completed

2.7 Change the URL of existing team site Go to Start  Run  type ‘inetmgr’ Expand the Web Sites and select WSS

2.8 website Right click Properties Select Web Site tab  Advanced Select the host header  click Edit Type the new Host Header Value : ABC.com” Click ok and close

2.9 Add entry in the hosts file Go to Start  Run  type ‘drivers’ Click on etc folder Open the hosts file in notepad Add a new entry for “ABC.com” Save & Close

2.9 Run upgrade and Migrate Go to Central Admin. Under Operations - Site Content Upgrade. Hit Begin Upgrade. Clear the port text box Type ABC.com in host header Select “Create new application pool” type “NewWssAppPool” in a application pool name specify user name and password Select “Manually set database names” in content database section

Click Ok Specify the temporary database name as WSSUP_Temp_”actual content database name” Click Ok

Customize MOSS 2007 ContextMenu

Introduction
Drop-down menus in Windows SharePoint Services and SharePoint Portal Server 2003 enable actions that relate to a specific document in a document library to be viewed and invoked. This article shows how these document context menus can be extended to add custom menu items. The document first explains how SharePoint document library context menus work, and then demonstrates how custom menu items can be added.

The Business Problem
Windows SharePoint Services (WSS) document libraries provide a location to store and share files and documents. The WSS user interface provides a context sensitive drop-down menu for each item stored in a document library (Figure 1). A common requirement is the ability to customise this menu to add new actions. For example you might wish to add an option to enable a document to be copied or moved to another location or emailed to a colleague.











Figure 1 Document context menu in a SharePoint Document Library
The solution and sample code presented in this article shows how a custom menu item can be created that sends an email link to the relevant document to another user.

Solution Overview
The WSS document context menu is generated by client-side Javascript. The script to display these menus is located in a file called ows.js in the folder \Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 on the SharePoint server. The AddDocLibMenuItems function in ows.js is responsible for generating the drop-down menus. The AddDocLibMenuItems implementation provides a hook through which additional menu items can be added to the context menu. The first few lines of this function read:

function AddDocLibMenuItems(m, ctx)
{
if (typeof(Custom_AddDocLibMenuItems) != “undefined”)
{
if (Custom_AddDocLibMenuItems(m, ctx))
return;
}

..etc..

This piece of code is checking whether a function called Custom_AddDocLibMenuItems is defined, and if it is then calling it. By implementing this function in a page containing a document library web part, we can extend the context menu, adding our own menu items
.

The Custom Menu Items Web Part
So, how can we add a custom piece of JavaScript to a SharePoint page? We need to make sure that the technique we use is configurable and flexible, and that we don’t change any of the built-in script or features of SharePoint so that our implementation is not overwritten by any SharePoint upgrades or service packs that may be deployed in the future.
Fortunately SharePoint provides a convenient mechanism for doing this – the Content Editor Web Part. The Content Editor Web Part enables custom HTML and script to be added to a page and delivered to the browser.


Adding the Web Part to a Page
In SharePoint, navigate to a page with a document library web part on it, or add one to an existing page.
On the Modify Shared Page menu, point to Add Web Parts and click on Browse.
Drag the Content Editor Web Part from the tool pane onto the page, then click Open Tool Pane link in the web part.
In the Layout section clear the Visible on Page checkbox. This means the web part is not visible to the end-user, but the script we add to the web part is still delivered to the client browser. In the page design view, you can still see the web part, but it is marked as hidden. If you wish you can also change the title of the web part in the Appearance section of the tool pane.








Figure 2 Hidden Web Part in Design View

From the tool pane, open the Source Editor and insert the following script:



Click Save in the Source Editor, and then click OK in the tool pane.
Now test the web part by opening a document library drop-down menu on the same page. You should see the new menu item at the top of the menu with a separator bar splitting it from the rest of the menu.


How It Works
The Custom_ AddDocLibMenuItems function takes two parameters. The first parameter, called m, represents the menu object itself; the second parameter, ctx, provides HTTP context information about the web request.
Adding a menu item to the menu requires just one function call:
CAMOpt(m, strDisplayText, strAction, strImagePath);

The CAMOpt function takes four parameters: the menu object to add the new item to, the display text of the menu item, the javascript action to perform when the item is clicked and a path to an image file to associate with the item.
A call to the CAMSep function adds the separator bar to the menu. Both these functions are defined in the menu.js file on the SharePoint server. Finally, the function returns false to the caller. This makes sure the standard menu items are also added to the menu; returning true indicates that these items should not be added.

Debugging the Web Part
To debug the web part, insert a debugger statement into the web part JavaScript:
debugger;
Provided a suitable debugger (such as Visual Studio.NET or the Microsoft Script Debugger) is installed, this statement causes Internet Explorer to break into the script when it is run, and offer the opportunity to start debugging.
Note: By default Internet Explorer disables script debugging. To make sure script debugging is enabled, open the Internet Options dialog from the Tools menu, and on the Advanced tab clear the Disable script debugging check box.
Once in the debugger, you can use the watch window to examine the variables that are available. Interesting variables to examine are m – the menu object, ctx which contains HTTP context information and itemTable which contains information about the list item the menu is associated with.

The Send Mail Web Part
Now we have figured out the principles of customising the drop down menus, the next step is to have them do something useful! The following script adds a menu item that sends an email link to the relevant document. It works by parsing the document URL out of the itemTable object and creating an action that instructs Internet Explorer to start a new mail message.
To use create this web part, simply follow the same steps that we used to create the Hello World menu item, using this script instead:





Clicking the custom menu item opens a new email message with the URL of the document in the body of the message.







Creating Custom Site Definition

Custom Site Definition with Custom Master Page MOSS 2007 & WSS 3.0
As a SharePoint administrator, if you want to customize your SharePoint sites, the first step is to create a custom site definition with a custom master page.
In order to create a new site definition, you pretty must have two options:
design from scratch or copy and edit the existing template.
The former will be more difficult than the latter. Designing your own site definition from scratch can be quite challenging if you are not comfortable with what you are doing.
In this exercise, I will explain the "easy" way to do this.
  1. You need to start with copying the existing site template from.
    On the server computer, browse to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\" folder. Each folder represents a site definition. Copy STS folder and paste with new name. In this exercise, we are going to name this site definition "Business" so rename it BUSINESS.
  2. In this site definition, a custom master page will be used because in the future, you might want to change the master page of the site definition and not unghost it. To do this, copy "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\default.master" file to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\BUSINESS" folder with its name changed to businesscustom.master.
  3. Open "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\BUSINESS\default.aspx" file with notepad. In the first line, changeMasterPageFile="~masterurl/default.master"toMasterPageFile="~masterurl/custom.master"Doing so will allow the default.aspx file to use the custom master page. Repeat this step for "defaultdws.aspx" file.
  4. Open "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\BUSINESS\xml\ONET.XML" file with notepad.
  5. Add the following line under tag:
  6. . Locate the first tag under tag.
  7. ChangetoNotice that I am assigning businesscustom.master value to MasterUrl.
  8. Locate tag under tag and add the following tag under tag:
  9. Repeat step 6-9 for and tags.
  10. Locate tag after and add the following lines to tag:

    Notice the file url is the assigned to the custom master page.
  11. So far, we have successfully created a site definition. All we have to do now is to register this definition to the site definition list. To do this, create "WEBTEMPBUSINESS.XML" file in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML" folder. Notice that there exists "WEBTEMP.XML" file in the folder and we are not editing this file. We are creating a new xml file to register a new custom site definition.
  12. Open the file with notepad and insert the following lines.
  13. Notice DisplayCategory="Corporation"; this will create a another tag named Corporation and the three items will be inserted to it. You can change titles, descriptions, and imageUrl's based on your needs. Save and close the notepad.
  14. Run IISreset.