Posts

How to Add onLoad JavaScript event in SharePoint?

SharePoint provides a JavaScript array “_spBodyOnLoadFunctionNames”, any function to be executed onLoad needs to be added to this array e.g. _spBodyOnLoadFunctionNames.push("ExecuteMyFunctionOnLoad"); Now, why does your JavaScript function doesn’t execute if you just register it with ClientScript.RegisterStartupScript? Actually, content pages can’t execute JavaScript function on body load, reason; content pages can’t directly add a function to the body’s OnLoad event if master page contains the <body> element (which is mostly true). This array is basically a part of init.js located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\”. If you open the javascript file, you will notice the page onLoad event is handled by function _spBodyOnLoadWrapper, which further calls ProcessDefaultOnLoad, and this function executes all the function names added in array "_spBodyOnLoadFunctionNames". function addLoadEvent ( func ) ...

CREATING AND DEPLOYING FEATURE IN MOSS

Image
Windows SharePoint Services 3.0 introduces an inherently portable and modular functionality known as feature, which provides a mechanism for defining site elements. A feature is a package of Windows SharePoint Services elements that can be activated for a specific scope and that helps users accomplish a particular goal or task. Features are added to a target site or site collection through a process known as feature activation. The element types that can be defined by a feature include menu commands, link commands, page templates, page instances, list definitions, list instances, event handlers, and workflows. So let’s start writing a feature. The functionality of the feature which we are going to develop is that it adds a menu item “Hello World” in the “Site Actions” menu. Clicking on the menu item “Hello World” will transfer to Google. Our goal is shown in the figure below: The first step is to understand the feature file structure. If you go to “C:\Program Files\Common Files\Microso...

MOSS 2007: Site Usage Report Error

Scenario: When click on “Site Usage Reports” under “Site Administration” in “Site Settings” page, the following message displayed: Both Windows SharePoint Services Usage logging and Office SharePoint Usage Processing must be enabled to view usage reports. Please contact your administrator to ensure that these services are enabled. Resolution: You have to enable two options. Open “Central Administration” -> “Operation” and click on “Usage analysis processing” under “Logging and Reporting” and check “Enable Logging”. Then, move to “Shared Service Provider”, Click on “Usage reporting” under “Office SharePoint Usage Reporting” and check both options.

Deleting Webparts When error occured

Sometimes it is difficult to delete or edit a web part. When clicked on “Modify Shared web part” link, error page appeared “An unexpected error has occurred. ” One way to delete the web part is to go to web part maintenance page and delete it. This can be done by adding “? contents=1” to default.aspx page.

How to programmatically Create SPListItem in a SPFolder

Sample Code to Create SPListItem in a SPFolder SPSite mySite = new SPSite( "http://[ServerName/sitename]" ); SPWeb web = mySite.OpenWeb(); SPList list = web.Lists[ "ListName" ]; SPFolder f = web.GetFolder( "http://[ServerName/sitename]/Lists/ListName/FolderName" ); if (f.Exists) { SPListItemCollection itemColl = list.Items; SPListItem item = itemColl.Add(f.ServerRelativeUrl , SPFileSystemObjectType.File, null ); item[ "Title" ] = "Added from Code" ; item.Update(); }

Create MySite Programmatically:

SharePoint provides APIs to create MySite programmtically. UserProfile object provides a method to create personal site. Following console application creates MySite for a given account: using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; using Microsoft.SharePoint; using System.Web; namespace UserProfileCreate { class Program { static void Main ( string [] args) { using (SPSite site = new SPSite( "http://servername" )) { ServerContext context = ServerContext.GetContext(site); UserProfileManager profileManager = new UserProfileManager(context); string accountName = "domainname\\username" ; UserProfile userProfile; if (profileManager.UserExists(accountName)) { userProfile = profileManager.GetUserProfile(accountName)...

Diff B/w SPSite & SPWeb

SPSite class : SPSite Represents a collection of sites on a virtual server, including a top-level site and all its subsites. Each SPSite object, or site collection, is represented within an SPSiteCollection object that consists of the collection of all site collections on the virtual server. SPSite.OpenWeb Method: Returns the site that is located at the specified server-relative or site-relative URL. SPWeb class : SPWeb Simply represents Windows SharePoint Services Web site. Code sample to create a site: SPSite mySite = new SPSite("http://servername/"); SPWeb myWeb = mySite.AllWebs["Site_Name"]; SPWeb myRootWeb = mySite.RootWeb; Note: SPSite and SPWeb inherit directly from System.Object Calling Dispose ensures all resources used by those objects are immediately released.