Speaking at KNUG – Karlstad .NET User Group

Speaking at KNUG – Karlstad .NET User Group

Yesterday I presented the MasterData Management using BizTalk 2006 R2 talk (I’ll soon have a post out with the presentation in English) I recently held at Developer Summit at the local .NET user group in Karlstad (KNUG).

KNUG is a new .NET user group that I actually helped start a couple of months ago. This meeting was the second meeting for the group. The meeting was attended by about 20 persons and we had two presentations on the agenda. Besides my own Thomas Heder showed the group some LINQ and how he and his colleagues uses LINQPad to develop and test there queries.

We also discussed future subjects, possible speakers and moving information on the group over to a Community Server driven site.

Does anyone have any experience on Community Server and how the feature set matches those need for running a user group (managing users, blogs, email lists, calendar etc)?

Don’t forget the BOM!

Don’t forget the BOM!

If you’re writing text files in an encoding that supports a Byte-Order
Mark
, you should always try to make sure that you include it, unless you have
a protocol in place that precludes you from doing so (such as a legacy application
that doesn’t know how to deal with them).

One of the reasons you should always remember the BOM is that many applications can
use it to try to guess what encoding they should use when trying to read the text
you’re feeding them.

Encoding detection based on the BOM is not foolproof, but it’s better than having
nothing at all, particularly in cases cases where simply assuming blindly a predefined
encoding such as UTF-8 or UTF-16 might not be an option at all.

One particular case where remembering the BOM is very important is with UTF-8. Let
me tell you a story to illustrate why:

We’ve been working the past few weeks on testing and improving a BizTalk-based solution
for a client that some other consulting company had created. One particular piece
had been working fine until, suddenly, we started getting an error when BizTalk tried
to parse an incoming message with an error stating that "The character is not
valid on the specified encoding".

Looking at the message, it was supposed to be UTF-8 encoded, and for the most part
looked OK. The character causing trouble was, in fact, a 0xA0 char (non-breaking space)
inside an element value. While this was not good, it wasn’t clear why it was causing
trouble.

Since it was an XML message, we opened it up in Internet Explorer: Yep, that too parsed
it incorrectly and got stuck when it reached the problematic character.

Looking a bit further , we found that in this particular case, the original developer
had written a piece of code that created a Stream object with the message contents
and then fed that to BizTalk. The code looked a bit like this:

public static Stream
CreateStream(String msg) {

   MemoryStream stream = new MemoryStream();

   byte[] bytes = Encoding.UTF8.GetBytes(msg);

   stream.Write(bytes, 0, bytes.Length);

   stream.Position = 0;

   return stream;

}

The message text itself was a piece of XML that included an <?xml?> declaration
with the encoding attribute specifying UTF-8. This seemed OK, even if the code above
just seemed like a pretty uncomfortable way of creating the stream.

However, this gave us a clue: UTF8Encoding.GetBytes() won’t give you
a BOM. Looking at the message in a binary editor, we validated indeed the message
did not have a BOM at all. So we tried replacing the code above to one that simply
used a StreamReader object (which uses UTF-8 with a BOM by default), and that fixed
the issue right away!

This highlights why the BOM is so important for UTF-8: The basic characters in the
set share the same values as the ASCII code. This is generally an advantage, but it
can also mean that stuff that’s incorrectly coded (such as our example above) might
seem to work fine for a while until an unexpected character comes along and everything
crumbles down. This is unlike other encoding, such as UTF-16, where things usually
blow up right away.

In this particular case, the culprit was really a combination of factors: The lack
of a BOM together with the presence of the encoding
specification
in the XML declaration [1]. I’m not sure why the XML stacks get
stuck on a BOM-less UTF-8 file with an encoding declaration, but there you have it.
So don’t forget the BOM!

[1] I personally thing the encoding specification in the XML declaration is
probably the single most stupid idea included in the XML spec. It’s just downright
evil.

technorati XML, .NET, BizTalk

BizTalk Server R3 trickle feed

Isn’t it fun how Microsoft trickle feeds us BizTalk information hungry souls with details about BizTalk Server R3? It is already in a TAP program so surely they know a lot about it…
Like Nick Heppleston’s “BizTalk to Incorporate Covast B2B Capabilities” postI am also concerned about them acquiring Covast’s B2B capabilities. It is on one […]

Article Series on BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

Whew.  My 9th and final article for TopXML.com on integrating BizTalk Server and WCF is now published.  This one looks at the BizTalk Adapter Pack and how to consume the Oracle adapter from inside BizTalk Server.  I demonstrated how to insert multiple records at once, call stored procedures, build a database polling solution, and how […]

Commerce Server 2007: Importing Excel Catalog Data

This just came up in the Commerce Server forums and I wanted to remind everyone that FarPoint Technologies has an Excel parser component (FarPoint Spread for BizTalk Server 2006) that can be used to create a simple process for uploading Excel catalog data into Commerce Server 2007.

The FarPoint website contains training videos, the case study I participated in, and lots of other technical information on this very cool tool!

If you missed my previous posts, you should take a look!

BizTalk Server 2006- Excel Parser News!

BizTalk Server 2006- FarPoint XLS File Pipeline Component Schema Wizard

BizTalk Server 2006- FarPoint Spread for BizTalk Server 2006 Beta

BizTalk Server 2006- FarPoint's Spread for BizTalk Server 2006 Released!

Just ping me at jeffrey.t.lynch@[nospam]comcast.net if you need a copy of my entire BizTalk solution for this. It's free of charge for any existing Commerce Server customer that buys the FarPoint Spread for BizTalk Server 2006 component as my way of saying thanks!

Best regards,

Jeff

Creating Hierarchical Menus with a CustomAction in SharePoint

Creating Hierarchical Menus with a CustomAction in SharePoint

It’s a fairly known technique to make use of CustomActions to add elements to the out-of-the-box user interface of SharePoint: you can add menu items to the Site Actions menu, you can add links on the Site Settings page, etc. The following piece of XML is the manifest of a feature that will add a new menu item to the Site Actions menu:


<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
    <CustomAction
        Id=”{B0B5A0CB-7FBE-4dd6-9B2A-2B1E1321B8F9}”
        Location=”Microsoft.SharePoint.StandardMenu”
        GroupId=”SiteActions”
        Title=”Dummy Menu Item”> 
    <UrlAction
        Url=”/_layouts/dummy.aspx”/>   
    </CustomAction>
</Elements>


For a more detailed description of CustomActions, I recommend following articles:



Another variation on this technique is to provide a reference to a class, instead of having fixed UI element specified in the XML. The following piece of XML points to the class ListSettingsMenu in the DemoCustomAction assembly.


<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
    <CustomAction 
        Id=”{42550415-FD08-4f1f-BAE6-93CCB2A2DE60}”
        Location=”Microsoft.SharePoint.StandardMenu”
        GroupId=”SiteActions”
        ControlAssembly=”DemoCustomAction”
        ControlClass=”DemoCustomAction.ListSettingsMenu”>
    </CustomAction>
</Elements>


The cool thing is that you now can write code that will render the UI element; it’s even possible to create a hierarchical menu. The following implementation of the ListSettingsMenu class, in combination with the XML from above, is adding one extra menu item to the Site Actions menu (List Settings). This new menu item will contain a sub menu item for every list on the site, these sub menu items will point to the settings pages of the corresponding lists. The ListSettingsMenu class inherits from the WebControl class, by overriding the CreateChildControls method, you can instantiate SubMenuTemplate and MenuItemTemplate instances, and add them to the Controls collection. An instance of the SubMenuItemTemplate class corresponds with a menu item that contains sub menu items. These sub menu items are instances of the MenuItemTemplate class. By setting the Text, Description and ImageUrl properties of these classes, you can specify how the menu items will be rendered in the SharePoint UI. The ClientOnClickNavigateUrl of the MenuItemTemplate class specifies the URL for the menu item itself.


namespace DemoCustomAction
{
    public class ListSettingsMenu: System.Web.UI.WebControls.WebControl
    {
        protected override void CreateChildControls()
        {
            SubMenuTemplate listSettings = new SubMenuTemplate();
            listSettings.Text = “List Settings”;
            listSettings.Description = “Manage settings for lists on this site”;
            listSettings.ImageUrl = “/_layouts/images/lg_ICASCX.gif”;


            foreach (SPList list in SPContext.Current.Web.Lists)
            {
                if (!list.Hidden)
                {
                    MenuItemTemplate listItem = new MenuItemTemplate();
                    listItem.Text = list.Title;
                    listItem.Description = string.Format(
                        “Manage settings for {0}”, list.Title);
                    listItem.ImageUrl = list.ImageUrl;


                    string url = string.Format(
                        “{0}/_layouts/listedit.aspx?List={{{1}}}”,
                        SPContext.Current.Web.Url, list.ID.ToString());
                    listItem.ClientOnClickNavigateUrl = url;


                    listSettings.Controls.Add(listItem);
                }
            }


            this.Controls.Add(listSettings);
        }
    }
}


To deploy all of this first of all the assembly (DLL) that contains the ListSettingsMenu should be built and copied either to the Global Assembly Cache or the BIN folder of the SharePoint site where you’d like to use it. Secondly the feature should be installed by copying the feature files and running STSADM -o installfeature -n featurename. Finally a SafeControl element must be added to the web.config, so the ListSettingsMenu control is marked as safe. If you forget the last step, you won’t get an error, but the extra menu item won’t be rendered. Here is a screenshot of the result:



The only caveat for this technique seems to be that you can’t use it to add a hierarchical menu in a EditControlBlock (ECB) CustomAction. The menu items of the ECB are rendered using Javascript. If you want to see a full blown example of what you can accomplish, check out the latest addition to the SmartTools project: the Enhanced Site Actions menu.

Creating Custom Application Pages that look like OOB Application Pages

Juist a quick post so I won’t forget this link: http://graegert.com/?p=505


Steve Graegert has written a great post on how you can work with the SPPropertyBag to store configuration settings. Of course that’s very interesting, but in this post he also describes how you can build a custom Application Page that looks like it’s an OOB Application Page. The trick is to know the SharePoint user controls that are responsible for building the UI, like InputFormSection and InputFormControl. Once again, check Steve’s post for the full details!


New Release of the SmartTools for SharePoint

I just uploaded a new release of the SmartTools for SharePoint to the CodePlex site. Currently the SmartTools project has two components:

Changes in this release:

  • What’s New v1.1
    • Fixed issue with Link items
    • Added option to Excluded or Include a list of content types
  • Autocomplete Text Field v1.1
    • Fixed an issue if the field was used as a Site Column
    • Added configurable delimiter characters to allow multiple lookups
Technorati Tags: sharepoint,wss,moss,smarttools