RSS

Tag Archives: web-part

SPS NOLA 2011 Presentation Materials

The materials (code and PowerPoint deck) from my presentation at SharePoint Saturday New Orleans 2011 can be downloaded using the following link:

Web Part Presentation Material (SkyDrive Folder)

I will also be posting the code to my CodePlex repository for online viewing.

 
Leave a comment

Posted by on February 26, 2011 in Speaking Engagements

 

Tags: , , , , , , ,

SharePoint Web Part XML Properties

When building a web part for SharePoint, you can use the .webpart file to set default values for almost all of the properties of that web part. But many people don’t know what those properties are or what they pertain to. Below is a listing of all the properties of an empty web part:

<webParts>
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
        <metaData>
            <type name=yourTypeHere" />
            <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
        </metaData>
        <data>
            <properties>
                <property name="AllowClose" type="bool">True</property>
                <property name="AllowConnect" type="bool">True</property>
                <property name="AllowEdit" type="bool">True</property>
                <property name="AllowHide" type="bool">True</property>
                <property name="AllowMinimize" type="bool">True</property>
                <property name="AllowZoneChange" type="bool">True</property>
                <property name="CatalogIconImageUrl" type="string" />
                <property name="ChromeState" type="chromestate">Normal</property>
                <property name="ChromeType" type="chrometype">Default</property>
                <property name="Description" type="string">My WebPart</property>
                <property name="Direction" type="direction">NotSet</property>
                <property name="ExportMode" type="exportmode">All</property>
                <property name="Height" type="unit" />
                <property name="HelpMode" type="helpmode">Navigate</property>
                <property name="HelpUrl" type="string" />
                <property name="Hidden" type="bool">False</property>
                <property name="Title" type="string">Web Part Title</property>
                <property name="TitleIconImageUrl" type="string" />
                <property name="TitleUrl" type="string" />
                <property name="Width" type="unit" />
            </properties>
        </data>
    </webPart>
</webParts>

For a definition and list of possible values for each of these properties, you can visit the MSDN pages for:

What about custom properties?

You can use SharePoint to create a reference for the properties of your web part. Install your web part, setup the web part the way you would like it by default, and then use the Verbs menu to Export the web part. Locate the exported file, open it in your favorite editor, and your XML is there!  Simple right?

 
Leave a comment

Posted by on November 23, 2010 in Microsoft SharePoint

 

Tags: , ,

Programmatically Update Web Part Properties

Have you ever wanted to give your users access to the personalized properties of a web part through a custom interface built into a web part? In ASP.NET, updating these properties and more importantly persisting the changes was a pretty straight forward process. Unfortunately, the same straight forward techniques can not be used when developing a SharePoint web part.

The code below is a very simple web part inheriting from System.Web.UI.WebControls.WebParts.WebPart. It consists of a TextBox and a Button but it illustrates a complete solution for persisting personalization changes to the SharePoint database programmatically.

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace UpdatePropertiesWithCode.UpdateMeWebPart
{
    public class UpdateMeWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected TextBox MessageTextBox;
        protected Button SaveButton;

        [Category("My Configuration")]
        [WebBrowsable(false)]
        [WebDescription("Message to display.")]
        [WebDisplayName("Message")]
[Personalizable(PersonalizationScope.User)]
public string Message { get; set; }

        protected override void CreateChildControls()
{
            MessageTextBox = new TextBox();
MessageTextBox.Text = this.Message;

            SaveButton = new Button();
SaveButton.Text = "Save";
SaveButton.Click += new EventHandler(SaveButtonClick);

            Controls.Add(MessageTextBox);
Controls.Add(SaveButton);
        }

        protected void SaveButtonClick(object sender, EventArgs e)
{
            this.Message = MessageTextBox.Text;

            SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(HttpContext.Current.Request.Url.ToString());
            SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.User);
            System.Web.UI.WebControls.WebParts.WebPart webPart = manager.WebParts[this.ID];
            ((UpdateMeWebPart)webPart).Message = this.Message;

            try
{
                web.AllowUnsafeUpdates = true;
manager.SaveChanges(webPart);
}
finally
{
web.AllowUnsafeUpdates = false;
}
        }
    }
}

 
Leave a comment

Posted by on November 12, 2010 in Microsoft SharePoint

 

Tags: , , , ,

Nov 18th Speaking Engagement

I’ll be presenting my Web Parts presentation for the Baton Rouge SharePoint User Group on Thursday, November 18th.

Update: This speaking engagement is tentative.

 
Leave a comment

Posted by on November 12, 2010 in Speaking Engagements

 

Tags: , , , , ,

Web Parts Presentation Materials

The materials (code and PowerPoint deck) from my presentation last night can be downloaded using the following link:

Web Part Presentation Material (.zip)

I will also be posting the code to my CodePlex repository for online viewing.

 
Leave a comment

Posted by on November 12, 2010 in Speaking Engagements

 

Tags: , , ,

November 11th Speaking Engagement

I will be presenting at the November 11th meeting of the Greater New Orleans SharePoint User Group. The topic will be SharePoint Web Parts and Best Practices. The presentation will focus on the 2010 product family and all code will be released after the presentation.

 
1 Comment

Posted by on October 25, 2010 in Speaking Engagements

 

Tags: , , , , ,

SharePoint Web Part Maintenance Page

On any web part page in SharePoint, you can append ?contents=1 to your query string to show the Web Part Maintenance page. For example: http://www.yourdomain.com/default.aspx?contents=1

This works in both SharePoint 2007 and SharePoint 2010.

 
Leave a comment

Posted by on July 28, 2010 in Microsoft SharePoint

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.

Join 57 other followers