Tuesday, August 3, 2010

How To: Enable IE 8 Compatibility View a SharePoint site

Today I found out about a cool new trick from Sing - enabling compatibility mode in IIS 7. When creating sites and especially SharePoint sites – new browsers like IE8 may not tolerate standards that have been implemented in web applications a while ago like MOSS and display your UI not the way you have it coded. Fortunately there is a way to force IE7 mode so that your browser will automatically load the page as it was loaded in IE7. An equivalent to you switching to compatibility mode:

This is done right on IIS level. Here is how:


1. Open your IIS and expand the site or directory you’re forcing compatibility on

2. Select Response Headers option

3. Create a new response header with below values, this will instruct IIS to emulate IE7:



That’s it just call an IISRESET and your site will not run under compatibility mode.
Please visit the Original Post here.

Updating SharePoint site columns programatically

Here is the scenario: you have a content type on the site that you use throughout on your items. You have a site column defined as a part of your content type. Suppose your site column is a choice field or a lookup and you want to make changes to available selection since some of the options in your choice field changed and you want them to reflect everywhere else in a content type.




Here is one of the approaches: site column is a special type of column and can only be accessed on the site level. To make changes to a column you will have to access the root SPWeb of your site and retrieve the field. As you will see below, many options are not part of the SPField object properties and depending on your needs you may have to set field properties of values through the schema XML wchih is both Read/Write.



Here is how something like this will look like from an feature event receiver executing on the root web of the site (you can port the code below to a console application as well):



public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

using (SPWeb rootWeb = properties.Feature.Parent as SPWeb)

{

if (rootWeb.Fields.ContainsField(ListConstants.MyColumnTitle))

{

SPList myList = rootWeb.Lists[ListConstants.MyListTitle];

SPField myField = rootWeb.Fields[ListConstants.MyColumnTitle];

string schema = myField.SchemaXml;

// here we’re adding additional element to a field definition within XML

schema = schema.Replace(“

myField.SchemaXml = schema;

myField.PushChangesToLists = true;

myField.Update();

}

}

}



Example above shows how you can access the List property of the lookup list even though it’s not available through the property selection – you can make appropriate chnages through schema. As soon as you update your changes – they will be pushed down to all of the content types that use the column. Good luck!

Visit the original post here.

Friday, July 16, 2010

Disable OK button in SharePoint using jQuery

Hi All,

It is really funny but today I come to know the real power of jquery. I know that jQuery is real cool dude in web world. However when I applied some stuff, it got my relief because it solved my two problems.

When you want to disable OK button in NewForm, Editform of list or document library in SharePoint, you can achieve this with the help of jQuery and it helps a lot. Let us say that you have some requirement like if status is suspended then nobody should be allowed to make any changes in the status field.

Let us add complexity to this. We have attached a workflow that triggers on update. Now the problem with SharePoint is even though nothing is updated, then also it triggers the workflow. So if you do not disable OK button and you go and click on edit item. And then when you do not update anything, click on OK. Boom...workflow triggers. Man…I don’t like this.

Here comes jQuery to save us. Disable the status and disable OK button. That will solve the purpose.

What do you need to do? Well, I have created dummy list to demonstrate this.

I have few fields and one of them is status. Statuses are New, In Progress, Archived and suspended.

When the status is suspended, I do not want to allow any of the users to change the status and also there is workflow attached to this list which triggers if we update any item. Workflow is attached from the SharePoint designer. Hence we are even not writing a code in event handler to check for the item has changed or not in ItemAdding event.

So write down this jQuery in content editor web part. Just add CEWP on top with appending &toolpaneview=2 to the URL.

Add following code to the content editor web part. If you observe we have taken reference of jquery from shared document. You can download the jQuery and then give href to the document library path. What we have done in this jQuery is simply finding all drop downs and then checking its value. If it’s suspended, then we are again checking button OK by its class and once found, we are disabling the button. Hummm…Easy ha? Yes it is.

How to impersonate user identity in WSS

Hi All,

There are some situations where in we need to change the executing code identity. Whenever code runs in WSS and in SharePoint, code actually executes in the logged in user’s identity. However this is not true in terms of workflow or the event handler where user does not play any identity role.

In these cases it is the system account that is considered as logged in user and all tasks are performed on that credential.

If we want to change the logged in user identity and make the code run on some other user’s identity at that time we can impersonate the identity of logged in user.

For example, in event handler or in workflow you want to change the user’s identity for executing code, you can do so with the help of SPUserToken class.

All we need to do is first take a reference of SPUser by getting user from SiteUsers method, and then pass the user token while initiating SPSite object. Once you do this, your code will run under specified user.

Before showing up the example, I would like to note here is that this process is different than RunWithElevatedPrivileges because this change of user token does not change the windows logged in user identity, it’s the User identity with respect to the WSS that changes. And the other important point to bring out here is that to perform the above mentioned code, your code first must run under RunWithElevatedPrivileges to user SPUserToken and change user.


SPSite objSite = SPContext.Current.Site;
SPWeb objWeb = SPContext.Current.Web;

SPUser objUser = objWeb.SiteUsers[@"domain\user"];
SPUserToken usertoken = objUser.UserToken;

using (SPSite SiteColl =
new SPSite(objSite.ID, usertoken)) {
using (SPWeb web =
SiteColl.OpenWeb(objWeb.ID)) {


}
}


That is it. you have just changed the User token while executing the code.

Thursday, July 15, 2010

Sharepoint 2010 Exams

Guys,

Now prepare yourself again for another set of MCTS exam for sharepoint 2010

This time also 4 exam but not like 2007 like 2 for wss and 2 for sharepoint.
All the exam this time will be for sharepoint 2010 with 4 part segregation

check out this links

70-667: TS: Microsoft SharePoint 2010, Configuring

70-668: PRO: Microsoft SharePoint 2010, Administrator

70-573: TS: Microsoft SharePoint 2010, Application Development

70-576: PRO: Designing and Developing Microsoft SharePoint 2010 Applications

P.S.: as per links about it shows
Published: July 12, 2010(In development) no idea about this published date