Tuesday, November 3, 2009

Activating the feature at sub site level

Avoiding manual activation of feature at the sub-site (web) levels


Add the ID (GUID) of the feature in Onet.xml file

Feature activation for timer jobs

A SharePoint feature receiver based on timer job is created as a site collection feature and you try to activate the feature

May throw the error message “EXECUTE permission denied on object 'proc_putObject'.

This is because adding the timer job is done by the account that runs the application pool of your web application. This account normally does not have write / execute permissions in the configuration database.

The best way to get around this is to change the scope of your feature to WebApplication. In a few examples on the internet, the feature is Site scoped. If you change it to WebApplication scope, you have to activate the feature in the Central Administration. The application pool that runs that web application has enough permission to do this. Of course you need to slightly modify the code of your feature receiver. Instead of casting the properties.Feature.Parent to a SPSite, you cast it to a SPWebApplication.

http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5-28d9-464f-b1c9-91e07c8f7e47&ID=82

Sharepoint Tips and tricks

1) We can Use single Content Type for multiple Page Layouts.
2) Always Use using(SPWeb/SPSite obj = new SPWeb()/SPSite() ) object. These two SharePoint object won't
get release from memory by GC and need to deallocate those explicitly

3) To Lock the block/method/event across the thread,
Create global object of object class and lock it.
private static readonly object objCentralLock = new object();

public override void Execute()
{
lock(objCentralLock)
{
......
}
}


4) SPJobDefinition(Timer job) Feature Development.
If the scope of feature is WebApplication then it will work fine. Otherwise it will throw database permission exception.
If you change it to WebApplication scope, you have to activate the feature in the Central Administration.
The application pool that runs that web application has enough permission to do this.
Of course you need to slightly modify the code of your feature receiver.
Instead of casting the properties.Feature.Parent to a SPSite, you cast it to a SPWebApplication.


100) Default page limit of sharepoint web for Navigation is 50. OOTB

to change this limit,Need to update web.config of perticular application.

Add DynamicChildLimt="XXXX" as attribute for all providers
1) GlobalNavSiteMapProvider
2) CombineNavSiteMapProvider
3) CurrentNavSiteMapProvider
4) CurrentNavSiteMapProviderNoEncode

XXXX is an integer number.

Tips and tricks(ASP .Net)

ASP.NET 1) To access requested page url
Page.Request.UrlReferrer.AbsoluteUri
2) Not to save page in browser's Cache
call Page.Response.Cache.SetNoStore(); Page.Response.Cache.SetAllowResponseInBrowserHistory(false);
in Base Master file's OnLoad() event or Page_Load() of page load event
3) To post any data as a Form's POST method use following class
3.1) First need to call Add() method to set fields name and values
Note: If it is asp.net target site and not handled Remote form posting request in Page_Load() then need to pass __ViewState value as parameter and also submit button type and ID should match to remote site page submit button. In this case remote site's button click event will get triggered automatically.
3.2) Post() method to post requset
public class RemotePost { string url; private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection(); public string Url { get { return url; } set { url = value; } } public string Method = "post"; public string FormName = "TestForm"; public void Add(string name, string value) { Inputs.Add(name, value); }
public void Post() { try { //Clear old respose System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Write(""); System.Web.HttpContext.Current.Response.Write(string.Format("")); System.Web.HttpContext.Current.Response.Write(string.Format("
", FormName, Method, Url)); //Add all parameters as html input hidden controls with id,name and value for (int i = 0; i < name="\" id="\" type="\" value="\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]])); } //Hide submit button System.Web.HttpContext.Current.Response.Write(string.Format("
")); System.Web.HttpContext.Current.Response.Write("
"); //trigger submit button click event using javascript click() method System.Web.HttpContext.Current.Response.Write(""); System.Web.HttpContext.Current.Response.Write(""); //Complete request HttpContext.Current.ApplicationInstance.CompleteRequest();
} catch (Exception ex) {
throw ex; }
} }
4) Force browser to download file(image filem .js or .css etc) from server then need to add querystring parameter where we have referening perticular filee.g. Here we are passing ?Version=1 value as a query string parameter and if file name from browser's temp folder and this mismatch thenbrower will download file from server and will refer latest one.If you modify CustomValidation.js file then you can add Version=2 value as query string parameter
This problem is mostly with IE 7.0 brower.
5) To determine who caused postback, use Request.Form["__EVENTTARGET"]. It holds the UniqueID of the control that caused postback.If the control is a button, its UseSubmitBehavior must be set to false. So in case you are getting nulls, you probably have UseSubmitBehavior=true.
6) Not to ask Remember Password or any field by any browser Add Autocomplete=off Attribute(like ControlID.Attribute.Add("Autocomplete","off");) to the User ID Textbox control.
7) Allow User to Read/Write/Delete disk file even if another user is using, Use FileShare mode with FileStream object as shown below.
using (FileStream fs = new FileStream("C:\\dat.txt", FileMode.Create, FileAccess.Write, FileShare.Write FileShare.Read FileShare.Delete)) { while (true) { fs.WriteByte(84); fs.Flush(); Console.Write("."); Thread.Sleep(1000); } }