Posts

Showing posts from 2009

WebPart Life Cycle

1. OnInit: event used to create controls of web part 2. OnLoad: 3. CreateChildControls: event used to set properties and default values to controls collection If the page is being rendered for the first time the method generally occurs after the OnLoad event. If it is Postback, It is called before OnLoad event. EnsureChildControls: It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it. 4. LoadViewState: The view state of the web part is populated over here. 5. OnPreRender: event used to set up business logic related work and in this routine controls value kept by viewstate 6. Render: event creates the HTML that appears in the body of the Web Part. 7. OnUnload: 8. Dispose:

Creating Views in SharePoint Using the object model

Using the object model we can create a SharePoint views programmatically. The query for the view uses an SPQuery which uses CAML. //Define an array to hold the columns required in the view String[] colArray = new String[] { "FName", "LName", "Email” }; //Add the array to a string collection StringCollection colCollection = new StringCollection(); colCollection.AddRange(colArray); //Define the query for the view String viewQry = “Your CAML Query Here’; HTML clipboard //Define the new view & Add to the List (100 is the item limit, true is allow paging and false is to set as the default view) SPView newView = YourList.Views.Add(“View Title”, colCollection, viewQry, 100, true, false);

How to modify the width and height of a Sharepoint Page Viewer web part dynamically

You can use following JavaScript code to dynamically adjust width and height of the page viewer web part. Just put it in each asp.net page that you want to display in a page viewer, and the problem will be solved: JavaScript code: function resizeMe(that) { window.resizeTo(document.body.scrollWidth, document.body.scrollHeight); } window.attachEvent("onload", function() { window.setTimeout("resizeMe()", 100); }); Alternatively, window.resizeTo(window.screen.availWidth, window.screen.availHeight); can also be used.

Adding Contact Selector Control to InfoPath form

The Contact Selector control is an ActiveX control but it is a special cased control, in that it can also be used in InfoPath browser forms. To use this control there are specific steps that need to be taken – let’s take a look at those now. Step 1 : Steps to add Contact Selector control to your Controls Task Pane 1) From the Controls Task Pane click "Add or Remove Custom Controls" link 2) Click the Add button 3) Add Custom Control Wizard select "ActiveX control" and click Next 4) This will display a list of controls , select "Contact Selector" ,click Next 5) Select “Don’t include a .cab file” and click Next 6) For Binding Property select Value and click Next 7) From the Field or group type box choose Field or group (any data type) and click Finish 8) Click Close and then click OK Step 2: Create the data structure for the Contact Selector Control The Contact Selector control needs to have a specific data structure to work properly – this is documented on

Diff between Site Pages Vs Application Pages

Site Pages: Pages that support user customization are known as site pages and stored in the content database. Ex. Site pages default.aspx, NewForm.aspx, and EditForm.aspx. Site pages customization provides flexibility but can also impact performance and scalability Each page would also have to be individually parsed and loaded into memory.. Site pages do not support in-line code under the default security policy enforced by WSS. Application pages: Application pages do not support customization, which gives them two distinct advantages over site pages. First, each application page is always compiled into a single DLL so that it performs and scales better than a site page. Second, application pages are allowed to have in-line code. Ex. Settings.aspx, uagedetails.aspx. Application pages are deployed as physical files on file system of front end web server on the server's file system. An application page, such as settings.aspx, can be accessed by adding its relative path within the _

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.