Writing Custom Web Parts for SharePoint 2007

Sahil Malik recently published a nice article that covers how to write a custom web part using ASP.NET 2.0 and host it within SharePoint 2007.

As I mentioned in an earlier blog post, SharePoint 2007 is built on top of ASP.NET 2.0, which means you can now use ASP.NET 2.0 features (Forms Authentication, Master Pages, Membership, Site Navigation, New Data Controls, etc) when building SharePoint sites.  This is true for both the new Windows SharePoint Services 3.0 version (which will be a free download) as well as Microsoft Office SharePoint Server 2007 (which costs money).

One of the cool developer scenarios is the ability to create your own Web Part controls that can be used in both SharePoint sites, as well as regular vanilla ASP.NET 2.0 applications.  This allows you to re-use all of the built-in SharePoint features for collaboration, document sharing, and content management - while also adding your own custom UI and behaviors (for example: if you want to integrate custom data editing and reporting to a site).

Sahil's article above describes how to create a Web Part control as a compiled custom control.  You can also now build Web Parts using ASP.NET User Controls (.ascx files) -- which makes composing and encapsulating UI functionality even easier.  Several people asked in follow-up comments to my previous post whether it will be possible to host Web Parts built as ASP.NET 2.0 User Controls within SharePoint 2007.  I checked with the SharePoint team, and they told me that this will be a supported scenario via an additional component you add to SharePoint -- and that they'll have a whitepaper and sample on how to-do this published later this year.

This Channel9 video of the SharePoint team provides more information about some of the cool new features in SharePoint 2007 (including its new Wiki feature support).  Mark Kruger also has a great list of SharePoint posts summarized here.  Sahil has a number of nice posts below that talk more about some of its customization/development scenarios that you might want to check out as well:

Fritz Onion wrote a great article last month that talks about how you can use the new Asynchronous features within ASP.NET to perform efficient network calls within a Web Part control without blocking the processing request thread.  This allows you to perform multiple network requests at the same time from different web parts and render the page much faster and more efficiently. 

Hope this helps,

Scott

23 Comments

  • Wow thanks for all the linkage Scott :).

    I just wanna point out (and this is also in the article), that - That article was written for Beta2, and it will certainly work on Beta2.

    However, going forward - my understanding is that in order to deploy new webparts, you put 'em either in the "bin" or in the GAC, not in "_app_bin" (as the article states).

    That is about the only thing that won't hold true Beta2TR onwards. Besides that - the article still holds good. In fact, after Beta2TR comes out, I am going to send in a list of fixes to the articles and keep 'em up-to-date.

    Much like I keep myself up to date by listening to Brittany shpearz music (ok not really).

    Later, :)

    SM

  • Sorry this is off-topic Scott but I couldn't find a Contact Me link anywhere on here.

    I haven't been able to find anything on Google or here on your site, so I figured I'd shoot you a message.

    I can create nested master pages using asp.net 2.0 and the new project-less model. But when using the Web Application Project, I always get errors on my content pages:

    "Cannot find ContentPlaceHolder 'MainContentPlaceHolder' in the master page '/Layouts/Trafalgar/MainLayout.master', verify content control's ContentPlaceHolderID attribute in the content page."

    Where my nested master "/Layouts/Trafalgar/MainLayout.master" has this @Master specified:

    MasterPageFile="../AllBrands/MainLayout.master"

    All the file paths are correct (if I mess one up I get a "cannot find" error), so it looks like this is something else.

    Again, sorry for using this comment for this question, but if you have any info I'd appreciate it. My email is adam@surrealization.com

    Thanks

  • Good to see so much stufffor sharepoint portal at one place

  • Thanks alot for another great post.

  • Hi Scott. Great news about the upcomming use of usercontrols as webparts - this is really a must have (today please or tomorrow at the latest :-).

    Next time you see those guys in the WSS and SharePoint team, please let them know that this is a urgent matter - creating advanced webparts in pure code is a complete waste of time.

    As always your blog is 100% informative and worth reading.

  • Thanks, Scott. Very up-to-date stuff.

  • Hi Scott, I've been reading your blog since one year and I learn in every post you publish. I've worked with Atlas and now I'm working with WebParts. My question is how we can mix these in Sharepoint, I mean, could I do webparts using Atlas to refresh the information (survey can be an example) ?

  • Hi Jaimie,

    Yep -- we are looking to enable developers to use Atlas with WebParts (for example: you can now use an UpdatePanel control within a webpart).

    Hope this helps,

    Scott

  • Hi Katy,

    Yep -- you should be able to use css, images and other files for custom controls in SharePoint. I believe SharePoint has the ability for you to add any of these files to its application directory structure -- in which case your controls could link to them directly.

    Hope this helps,

    Scott

  • hi, still remember a topic discussing about using ASP.NET user control in sharepoint 2007 webpart around july/august.

    Would like to know is the solution roll out by microsoft team already? thanks for information.

  • Hi Michael,

    You will be able to use ASP.NET User Controls as full MOSS web parts later this year when an additional module is provided on-top of MOSS that hosts them. The SharePoint team is actively working with someone right now to make this available around the time SharePoint 2007 ships.

    Hope this helps,

    Scott

  • Dear ScottGu,

    I am a newbie in programming under Share Point, so I would high appreciate any hints or directions where I can move to.

    I have Share Point 2007 (beta) installed with SharePoint Designer 2007.
    I need to connect Outlook 2003 and my site on Share Point 2007. in other words, at the moment I have received e-mail at the Outllok 2003 I want to see this mail at my site on Share Point 2007.

    Is it possible? How can I do it?

    Thank you

    Dan

  • hi scott,
    I am reading your blogs always. They are really interesting. I am working on a project using sharepoint services 3.0. And customizing a site using sharePoint designer. I need to integrate asp.net atlas into it. Is it possible? Then can you please give me some links on this topic.
    Charith

  • Hi Charith,

    We are working on integrating ASP.NET AJAX into SharePoint 2007 now. We will hopefully have a patch for SharePoint that enables some good ASP.NET AJAX integration next year.

    Hope this helps,

    Scott

  • Hi all,
    Somebody knows how to apply .skin file into sharepoint 2007 custom user controls?
    Thanks

    Marc

  • hi Scott

    Is that possible now?
    Also, when can we expect full ATLAS integration?

    cheers
    pascal

  • Hi Pascal,

    You can now use ASP.NET 2.0 User Control Web Parts using this control: http://weblogs.asp.net/jan/archive/2006/12/02/announcing-the-return-of-the-smartpart.aspx

    Hope this helps,

    Scott

  • Hi Scott
    Do you have any idea when the add-on for user controls for Sharepoint is coming out? I am aware of the Smart Part but is Microsoft coming out with its own add-on?

    Thanks
    Daragh

  • Scott,

    Any specific dates floating around for the official release of this add-on support for User Controls in MOSS?

    thanks

  • Hi JJ,

    Here is a pointer to the SmartPart control that supports hosting ASP.NET 2.0 user controls in SharePoint 2007: http://weblogs.asp.net/jan/archive/2006/12/02/announcing-the-return-of-the-smartpart.aspx

    Hope this helps,

    Scott

  • Hello, Scott. Echoing Daragh's question: Is MS planning on implementing SmartPart-like functionality sans third party stuff?

  • Hi Merc,

    I believe it is being planned for a future release, but right now it is best to use the SmartPart control to achieve this.

    Thanks,

    Scott

  • I have created a web part that is accessing an XMl file. I am using this webpart on site hosted on Ms Sharepoint server 2007 . But it gives error as "File does not exist". I made sure that file exist at the location specified. Can anyone please help me out?

    Thanks in Advance.

Comments have been disabled for this content.