Son of SmartPart Quickstart

This article will show you how you can create your first .NET 2.0 user control and show it in a SharePoint site. First you need to deploy the Son of SmartPart to your SharePoint server of course. Check the Installation Guide which you can find in the zip file that can be downloaded from www.smartpart.info, or watch this installation screencast. When this is done, open up your brand new Visual Studio 2005 and create a new ASP.NET Website. In the Website menu choose “Add new item”, and add a new Web User Control to the project, named DemoControl.asxc.

Now let’s implement the desired functionality! Drag-and-drop a Calendar control from your toolbox on the newly created Web User Control. You can do this both in design and source view, but in the source view you immediately see the result. You can use the SmartTag to Auto Format the control, I’ve selected the professional look of course. :-)

It’s time to write some code so switch to code view, and in the Page_Load event write following code:

public partial class DemoControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Calendar1.Width = new Unit("100%");
        Calendar1.SelectionMode = CalendarSelectionMode.None;
        Calendar1.TodaysDate = DateTime.Now;
    }
}

Optionally you can test your user control by putting it on your default.aspx page for example. But lets immediately fast forward to the deployment of your work to SharePoint. Open the folder in which your web site is located (typically \My Documents\Visual Studio 2005\WebSites\NameOfSite) and copy DemoControl.ascx and DemoControl.ascx.cs to the \UserControls folder of your SharePoint site (check the installation guide if you don’t know what I’m talking about). Next you can open the SharePoint site where you’d like to add the user control as a web part. On the top right of the page, click “Modify Shared Page”, “Add Web Parts”, “Browse” and drag-and-drop an instance of the SonOfSmartPart UC web part to your page.

Click the “Open the tool pane” link on the SmartPart and select the “usercontrols_democontrol_ascx” from the top drop down. Additionally you can also choose a title for your web part. When you’re done click the OK button at the bottom of the page. Now you’re ASP.NET 2.0 UserControl is displayed in a SharePoint site!

27 Comments

  • Is there any way to use gridview which pulls the data from database??? Unfortunatly I'm getting err when I'm tring to ad myGridview i see the info in dropdown list "Could not load myGridview.ascx"

  • I could create a smartpart.wssdemo.com site and give you an ftp connection to the the UserControls folder if you don't find any other hosting solution...

  • Hi,



    first I want to thank for your great blog!



    I have a question about Son of SmartPart: I'm new to Web Part development, but when I understand it right, a Web Part especially makes sense in using the main portal features like single sign on or personalisation. (How) Is it possible to embed the SmartPart Web Part into this funcionality - or is it just a way to display a web part offering some proprietary funcions but no connection to the sharepoint techniques itself?



    Thanks a lot for your hints!



    Nikolas

    dongiovanni@gmx.de

  • I am having a problem with Son of SmartPart on a fresh install of WSS/SP2. Just a new Team site and adding the Son of SmartPart UC. I get this error in the top section of the Tool Pane



    Could not open user control path: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Webs\STS\UserControls'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption) at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) at System.IO.Directory.GetFiles(String path) at SonOfSmartPart.UserControlToolpart.RenderToolPart(HtmlTextWriter output)





    I ahve been searching and have not found a solution. I am fairly new to WSS but I have set it up for clients and development teams many times so I feel fairly confident the install is good. I have another server running a intranet portal and have not run into this before.



    Thank you

    bill

  • Have you created the UserControls folder over here: 'C:\Webs\STS\UserControls'



    Maybe the account running SharePoint has no rights for that folder?

  • Jan



    Man I missed that! Been reading too many books and papers lately. I had added the directory but spelled it as ":\Webs\STS\UserControl". When I was trying to figure this out I was blinded by my mind. It said my eyes saw a matching path, so that was cool. When I read your response I first RDP'd to the server and checked the path. Ahhhh a missing S! Renamed and connected and all is once again happy in my little neighborhood ;-)



    Jan Thank you for taking the time to reply to what was an obviously "DUMB" mistake.



    bill

  • Jan,
    I am trying to do a proof of concept on WSS V3 using "son of smart part" interface developed by you (Kudos on that!!!).
    While I have played extensively with it, what I am finding extremely difficult to achieve is to create a drop-down Property using your interface. I have successfully created the checkbox, textbox properties, but while I am using "enum" - this just shows up as a simple Text Box in the properties section of WSS V3.
    I am using vb.net to build user controls.
    I can send you the code if needed,

  • Jan,
    Were you able to find some time to play with the WSS v3 and how your son of smart part will work with this. I have been checking my post several times but I think you are busy with something else.
    Anyone else having any idea on how to create a drop down property in wss v3 using Jan's interface, please reply...
    Thanks,
    Mayur

  • I cant use database. whenever I add a ascx page containing a connection to database I get an error

    Can someone post a sample or tutorial of how to use son of smartpart using database connection?

    thanks

  • Thanks a lot Jane this son of smartpart helped me a lot.

  • I installed the SonOnSmartPart according to the instructions.
    I keep getting an error:
    A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.

    I completed step 4 of the instructions.

    What else should I check.

    I've also cycled IIS.

    Thanks
    Ron

  • How can you debug (brakpoints) user controls hosted inside SOSP?

    I'm using VS2005 and WSS2.0

    Thanks
    JFP

  • Hi my name is Robert. I am using Son of smartpart to display user control with graph and controls. I have applied one dll file in my user control and the website run correctly but when I am applying this user control to sharepoint 2007 site it shows the below error:
    "Error: unable to load /UserControls\viewspice.ascx
    Details: c:\Inetpub\wwwroot\wss\VirtualDirectories\80\UserControls\viewspice.ascx.cs(17): error CS0246: The type or namespace name 'spice' could not be found (are you missing a using directive or an assembly reference?)" And I have already applied that dll and name space to the project I do not understand why its happening? If anybody help me it will be great.

    Thanks all.

  • I am facing same problem like Robert malvino mentioned above. I created user control with Charts using Dundas charts.
    I copied the DUndas DLL and usercontrol dll to the bin folder but WSS cannot load the control.
    I think since dundas is a separately licensed software, I am facing this issue. is there a way to make this user control show on sharepoint site?
    Thanks

  • Hi all,

    How can I expose properties from the user control to the sonofsmartpart properties panel ?

    Thanks

  • Thanks for Son of SmartPart! Great component!

    Now I also want to know how to expose properties
    from the user control to the sonofsmartpart properties panel.

    I want to use properties such as DB connection string etc
    or else my user control won't do much.

    Or I could use a SharePoint list to store the necessary
    properties, but I really don't think that is the right way to do that.

    Thanks a lot in advance

    Javier

  • Hi Jan,

    I am trying to use the Son of SmartPart and deploy it in WSS 3.0. However, when I have deployed my content in WSS 3.0 by importing the DWP using the Site Actions menu rather than creating a WPCatalog directory in the root of the Sharepoint folder, I get an error message when attempting to execute my web part with a message of "File Not Found". I have looked for any solution to this but have not found any as of yet.

    Do you know why this might be occurring?

    Thanks.

    Samir Vaidya
    ssvaidya@mail2architect.com

  • I get the same error as others.

    "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe."

    Why dont you post a solution.

  • I found the solution. you have to force the upgrade of Sharepoint to 2.0. I found it on another site. It would still be helpful to post complete step by step instructions to lead us that don't know what they are doing.

  • Hi all.

    I'm using SonOfSmartPart with WSS 2.0, Windows Server 2003, .NET 2.0. All works fine, but only if i use an account which belongs to the local administrator group on the WSS-Server. If i move my Domain-Users in the local admin-group, all works.
    In any other case i get a "Access denied..."-Message from WSS.
    This is true, even if i want to access a site with an empty SonOfSmartPart-WebPart, so it does not seem to be a problem with my user controls.

    Does anyone has a solution for this?


    Thanks in advance

  • Thanks, now I know a little bit more how to use SmartPart with wss 3.0 and with Visual Studio 2005. One question: how to create connectable web parts using smartpart and VS 2005?
    Would be grateful for an answer.

    Thanks in advance

  • Lucy! Please call me,Lucy! Please call me

  • Lucy! Please call me,Lucy! Please call me

  • I'm getting a message saying:

    Error: unable to load ~\/UserControls\cLookup.ascx
    Details: That assembly does not allow partially trusted callers.

    When I try to load my ascx. It has a purchased control in it, which I put the associated BIN file in the BIN folder for the WSS Virtual Directory. Can You give me any pointers here?

    frank.walsh[at]gmail.com

    Thanks

  • I have managed to add the SmartPart WebPart to a page, but the "User Control to display" drop-down is populated with "could not load DemoControl.ascx".

    I then get the following error:

    Error: unable to load ~\/UserControls\DemoControl.ascx
    Details: The file /UserControls/DemoControl.ascx does not exist.

    Does anybody have any ideas? The DemoControl.ascx file certainly does exist.

    Many thanks

  • Hi. When I use SmartPart on a form based authenticated site, I get "Access to the specified path denied" error. I allowed permissions at UserControls directory for web sharing, but could not understand the reason. What is the problem here?

  • I am having problems with getting a web part using son of smartpart to be both a consumer and a provider. First, is this possible and if so what is the trick to make it work?

    Thanks

Comments have been disabled for this content.