background preloader

SharePoint Development

Facebook Twitter

Using ASP.NET Web User Control with Code Behind in SharePoint. May 6 2008 What are we trying to do?

Using ASP.NET Web User Control with Code Behind in SharePoint

Let's say you want to create an ASP.NET page in SharePoint site. HelloWorld.aspx and put it in ~site/_layouts/HelloWorld.aspx. Insert a CustomValidator in a SharePoint Form (New/Edit) Sometimes you need to perform some validation on the input of a user in EditForm.aspx or NewForm.aspx.

Insert a CustomValidator in a SharePoint Form (New/Edit)

I saw some people validating the input in the SPItemEventReceiver and throwing an ugly exception. Not sure your user will not panic by the error message... Come on guys, we can provide some more useful validation tips! Sure you can write your own custom field (or inherits from an existing one) but this is fastidious work. What about checking whether the "EndDate" is later than "StartDate"? Here is a preview of the final solution: Required Field Validator for SharePoint People Editor « Chanakya Jayabalan's Blog. I used SharePoint People Editor control in custom asp.Net web part.I wanted to check for required field.

Required Field Validator for SharePoint People Editor « Chanakya Jayabalan's Blog

I have tried using the property Allow Empty, but unfortunately it doesn’t work. I have used a Required field validator. Luckily it works to some extent. But the problem starts if there is any post back happening on the page. After the post back, it takes the value to be empty even if there is an entry in the control. I got to get a javascript that checks if the control is empty and stores the results of the validation in the IsValid property of the ServerValidateEventArgs object. Here is the script and a custom validator we need to use to check e\whether the people editor control is empty or not. <script type=”text/javascript” language=”javascript”> function CheckBusinessExcellence(source, arguments) Why do SharePoint Projects Fail – Part 5. Hi again and welcome to this seemingly endless series of posts on the topic of SharePoint projects gone bad.

Why do SharePoint Projects Fail – Part 5

We spent a couple of posts looking at problem projects in general before focusing specifically on SharePoint. If you have followed the series closely, you will observe that haven’t talked much on technical aspects of the product yet. If you were expecting me to pick apart annoying aspects of the architecture then unfortunately, you will be disappointed because I really don’t believe that it is a big factor in why SharePoint projects fail.

Besides which, 90% of SharePoint blogs are on technical/development content anyway. So where am I going with part 5 then you ask? So now its time to take a few cheap-shots at the geeks. Geeks can also cop it like Project Managers do, when projects take on wicked tendencies. In some ways the geeks have an easier job than others in the project (but don’t tell them that you will bruise their ego’s). Product Complexity – Infrastructure. When not to use SharePoint. A former student sent me an e-mail asking when SharePoint would be a misguided approach to creating a solution, and I consider this to be a pretty important question to be asking and answering for every project.

When not to use SharePoint

Here was my response: The overarching idea is not to fully use SharePoint as a framework for something that leverages no part of it. Since you can code anything you want the second you fire up Visual Studio, you could start to think of SharePoint as purely a platform, and just go from there to make whatever it is that you would like. The second you realize that the lists, the page architecture, the content types, or any other fundamental aspect of what SharePoint offers are really just getting in the way of your design goal, it’s time to take a step back and revisit whether you should be using SharePoint at all for that particular project.

Forms aspx

How to avoid the Top 5 SharePoint Performance Mistakes Application Performance. SharePoint is without question a fast-growing platform and Microsoft is making lots of money with it.

How to avoid the Top 5 SharePoint Performance Mistakes Application Performance

It’s been around for almost a decade and grew from a small list and document management application into an application development platform on top of ASP.NET using its own API to manage content in the SharePoint Content Database. Over the years many things have changed – but some haven’t – like – SharePoint still uses a single database table to store ALL items in any SharePoint List. And this brings me straight into the #1 problem I have seen when working with companies that implemented their own solution based on SharePoint. #1: Iterating through SPList Items As a developer I get access to a SPList object – either using it from my current SPContext or creating a SPList object to access a list identified by its name. Looks good – right? 200 SQL Statements get executed when iterating through SPList.Items #2: Requesting too much data from the content database Final words. Using SPContext.Current is no guarantee for great performance.

It is a common best practice, while working with the SharePoint server API, to always use context objects whenever possible.

Using SPContext.Current is no guarantee for great performance

Because they have been already instantiated by SharePoint itself, reusing context data doesn’t cause additional calls to the database and allows you to create good performing solutions. However, just because you use SPContext.Current in your code, doesn’t mean your solution is built properly. An easy example of how things can go wrong Imagine the following scenario. You have a Page Library with some Publishing Pages in it that you provisioned together with your Web Template.

To include the value of the MetaDescription column as a meta tag in your page you created a custom control and added it to the head section of the page in the Master Page. When you refresh the page and view the HTML source, you should see the meta description tag rendered – just as expected.

Lists[name] vs getList(url)

Using the Developer Dashboard - SharePoint 2010 - Articles. SharePoint 2010 has many new features, among them, the Developer Dashboard.

Using the Developer Dashboard - SharePoint 2010 - Articles

This is a dashboard for analyzing the execution and performance of the current page. The information provided will execution time of queries and events to more general information as the user logged on or page state. By default this feature is not enabled. You can choose between four methods to activate it: a STSADM command, a PowerShell script, a .NET code or the Developer Dashboard configuration feature. There are three levels of activation: Off: Disabled, this is the default value.On: The feature is available on all pagesOnDemand: An icon is displayed on the pages to enable or disable the feature. The state OnDemand is, in my opinion, the most practical because you can do this only on the pages under development.

This operation requires that you be administrator of the SharePoint farm. The command line tool, STSADM, is one of the methods for modifying the activation status of the Developer Dashboard. Disposing SharePoint objects - what they don't tell you. If you're a SharePoint developer and find yourself regularly writing code to work with SPListItem objects, here's some info which might help you factor your code in a slightly neater way in some scenarios.

Disposing SharePoint objects - what they don't tell you

Interestingly this doesn't get mentioned in any of the key papers/articles - I can think of a good reason for this (which we'll look at), but in my mind this is a safe technique. If you have other ideas however, I'd love to hear from you. Most developers are now fairly well-versed in the techniques needed to write efficient SharePoint code (key resources are listed at the end of the article), specifically in terms of disposing of any SPSite/SPWeb objects your code creates.

The thing is, having to always be mindful of disposing these objects can sometimes restrict us in the way we want to write our code - consider the following simplified example: public void DoSomething(){ SPList list = getList(); // do something with list.. foreach (SPListItem item in list.Items) { processItem(item); } SharePoint Fix: SharePoint 2010 - Do not dispose guidance for SharePoint objects.

Do not dispose the following listed SharePoint objects explicitly: (Applicable for both SharePoint 2010 and SharePoint 2007) •SPContext.Current.Site •SPContext.Current.Web •SPContext.Site.

SharePoint Fix: SharePoint 2010 - Do not dispose guidance for SharePoint objects

Best Practices with Event Receivers. Published: May 2010 This topic addresses common issues related to efficient use of event receivers. Do not instantiate an SPWeb, SPSite, SPList, or SPListItem object within an event receiver. Event receivers that instantiate these objects instead of using the instances passed via the event properties can cause the following issues: Significant additional roundtrips to the database (one write operation can result in up to five additional roundtrips in each event receiver). Calls to the Update method on these instances can cause subsequent Update calls in other registered event receivers to fail. Bad Coding Practice. Security Best Practices for Developers in SharePoint 2010. Elevation of privilege results from giving an attacker authorization permissions beyond those that are initially granted. For example, an attacker with a privilege set of "read only" permissions somehow elevates the set to include "read and write.

" For more information, see Elevation of Privilege. Check User Permissions Appropriately In some cases, your feature may not automatically check permissions. Developing Applications for SharePoint 2010. Patterns & practices Developer Center June 2010 SharePoint 2010 introduces rich new areas of functionality that create more choices and fresh opportunities for developers and solution architects. Sandboxed solutions, new options for data modeling and data access, and new client programming models with Silverlight and Ajax integration offer a step change in what you can accomplish with SharePoint applications. This guidance provides a deep technical insight into the key concepts and issues for SharePoint 2010 solution developers. Overview Getting Started Community Future Plans Feedback and Support Authors and Contributors Related Titles.