SmartPart for SharePoint Released!

For those of you who don’t know the SmartPart for SharePoint; a little introduction:A SharePoint web part that can host any ASP.NET user control. Create your web parts by using the VS.NET designer instead of coding everything by hand!

In the last weeks Fons and I have worked on some cool new functionality, you can download the new release (version from the GotDotNet Workspace. To install the SmartPart, execute the MSI Package that’s included. Due to some internal changes, the SmartPart assembly must be deployed to the Global Assembly Cache (GAC), hence if you’re prompted by the installer, choose ‘Yes’. For this release you need to manually alter the web.config file and set the trust level in the system.web section to WSS_Medium (see the readme file for more info). I’m working on this to avoid the manual intervention (already many thanks to Maxim for his help). So, what’s the cool new stuff in this release?

  • Exposing user control properties in the properties toolpane. In the previous versions you needed to implement the IPropertyProvider interface so the SmartPart properties toolpane would display some properties of the user control it contained. These days are over, you can now add the Browsable attribute to every property you want to be exposed. That’s it! By using the Description attribute you can control the caption of the property in the toolpane. Both attributes are in the System.Componentmodel namespace.

  • Dropdown list for easy selection of user controls. In the previous versions the location of the user control needed to entered manually (e.g. “~\UserControls\HelloWorld.ascx”). In the new version you can choose between two web parts: one similar to version 0.1.x (with a textbox as input) and another one with a dropdown list that contains all available user controls. By default the SmartPart List web part will look in the \UserControls directory which user controls are available. If you prefer another location, you can easily change it in the DWP file.

To illustrate how to use the new stuff and to show how easy it is, let’s create a small demo web part. Let’s create a web part that displays the name of the currently logged on user. In Visual Studio, create a new ASP.NET Web Application. Add a new Web User Control to the project, for example UserInfo.ascx. Add a reference to the SmartPart.dll, which is included in the download, and to the Microsoft.SharePoint dll, which you can find on your SharePoint server. Suppose we want to be able to let the user choose a prefix that should appear in front of the user name (e.g. “Current user John Doe”). So we’ll need to create a property Prefix and decorate it with the Browsable attribute. For a good user experience we also add the Description attribute to specify how the property is presented to the user. Add a Label control that will contain the actual text. Because we want to display the user that is currently logged on, we’ll need access to the SharePoint object model. That’s quite easy, just implement the SmartPart.IUserControl interface. Finally we need to add the code to display the prefix and username to the Page_Load function. To finish of, you can add a Description attribute to the class too, so it gets a nice name in the SmartPart dropdown list. The complete code of the user control could look like this:

[System.ComponentModel.Description("Hello World Demo")]
public class UserInfo : System.Web.UI.UserControl, SmartPart.IUserControl
            private string _prefix = null;
            protected System.Web.UI.WebControls.Label Label1;
            private Microsoft.SharePoint.SPWeb _web;
             System.ComponentModel.Description("Prefix to display")]
            public string Prefix 
            {          get { return _prefix; }
                        set { _prefix = value; } }
            public Microsoft.SharePoint.SPWeb SPWeb 
            {          get       { return _web; }
                        set       { _web = value;          } }
            private void Page_Load(object sender, System.EventArgs e)
                        Label1.Text = this.Prefix + this.SPWeb.CurrentUser.Name;
            #region Web Form Designer generated code
            // Left out..

After you’ve build the project, the deployment can start. You need to copy two files: copy the UserInfo.ascx to the \UserControl folder in the folder that maps to your SharePoint site (e.g. C:\Inetpub\wwwroot\UserControls) and copy the UserInfo.dll to the \Bin folder (e.g. C:\Inetpub\wwwroot\Bin). If the UserControls folder does not exist, you can create it (it’s not a default SharePoint folder). Now drag-and-drop an instance of the SmartPart List web part to a site, and choose the “Hello World Demo” control from the drop down list.


  • GREAT! This is just fantastic stuff!!! :)

  • Great stuff. Adding the list is an excellent idea.

    Are you taking suggestions for the next iteration? If so, I have one. Currently you can use SmartPart's libraries in the user control to call Sharepoint. This is obviously very useful. The next step from this, I would think, would be the ability to compile a user control, using SmartPart's facilities, that would be exposed to the world as a full-fledged web part. It would have a separate entry in the web part list, its own name on the title, and no SmartPart user control list dropdown.

    This would represent what I would think would be a kind of holy grail: The ability to use user controls' full design mode facilities to create a web part.

  • This is f00kin' awesome! Very rawkin'! I got this goin' no problem. You guys are my fathers!

  • Update: Is not Oracle what is causing problems...all user controls cause them. Even if recompiled with v0.2 of the smartpart.dll. The browsable properties and the list of controls are shown though.

  • Final update: Got them working now. The problem was I kept using the UpdateControl function that is no longer valid.

  • Sure! its one of those wonderful controls. I downloaded and installed on the on all VIRTUAL SERVER on the Sharepoint server. However in any of the SharePoint site, this webpart is not showing up. I just simply ran the latest version MSI package.

    What am I missing? I also added the <TRUST> as mentioned in the readme file.

    Also do you know where are all these web parts are located on the sharepoint server?

    Also I couldn't locate your .DWP file?


  • I installed as it is saied bu i can't run it in SharedPoint. The error is:


    Error: unable to load ~\UserControls\UserInfo.ascx

    Details: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (c:\inetpub\wwwroot\UserControls\web.config line 102)

    I made the UserCOntrols virtual folder a IIS Application, I add trust tag in web.config but it is still the same.

    What is wrong?

  • Hi Jan & Fons, Great stuff .... with only some issues on Sessions but viewstates are working fine but storing dataset may cause some bandwidth overheads. Anyone out there got Sessions to work with Smartparts. Looking forward to tryout

  • How can we expose properties (that are also personalizeable) with Return of SmartPart? I tried the above but didnt work. Thanks.

  • I am using your smartpart but i have a problem..........!
    i am not able to retrieve any sharepoint lists. SpWeb property is turning out to be null.......!

    am i doing any mistake ???

  • Where can I download an older version of SmartPart. That is SmartPart for SharePoint 2003

  • Hai

    i did everything but i did not get answer... the label display only blank...

  • where can i get that smar part that is not available in gotdotnet side

Comments have been disabled for this content.