Archive for web part

While I’m here…….

Posted in InfoPath, SharePoint, Snippets with tags , , , , , , , on April 25, 2008 by Si

I remembered a couple of other little SharePoint snippets that I have found useful.

  1. Want to use that lovely green spinning icon that SharePoint uses when its doing something? Try the SPLongOperation class – good example here.
  2. Need to set the audience for a webpart through code? This is what I used!.
  3. Get the current user in InfoPath (not strictly SharePoint, but uses the SharePoint web services). Read this.
  4. Convert the XML that SharePoint returns into a dataset (I find myself using this all the time, probably because I don’t know better!):


public DataSet NSXmlToDataSet(string xmlString)
{
DataSet ds = new DataSet();
XmlDocument xd = new XmlDocument();

xd.LoadXml(xmlString);

XmlNamespaceManager nsMgr = new
XmlNamespaceManager(xd.NameTable);
nsMgr.AddNamespace("rs",
xd.DocumentElement.GetNamespaceOfPrefix("rs"));

XmlNode xn = xd.SelectSingleNode("//rs:data", nsMgr);

XmlNodeReader reader = new XmlNodeReader(xn);
ds.ReadXml(reader);

return ds;
}

Si

Now you see it, now you don’t

Posted in SharePoint with tags , , on April 23, 2008 by Si

A lovely thing is a SharePoint document library. Well it is until users are added in to the equation. At which point, either you don’t want them using the toolbar, or they don’t want to see it (or bits of it). Fair enough, just go into the web part properties and hide the blasted toolbar. Job done! Well, no, because if I wanted to template that site and use it again (which I often do), the toolbar settings don’t get saved so I have to go back in and turn them off. Boring!!

So I set about creating a feature that would enable me to quickly set up a site and configure all the different bits, and all was going well until I tried to get at this toolbar setting. You see, its not directly available through the SharePoint object model, and is hard to get at using System.Reflection (I tried lots of code posted on other sites, none seemed to work for me – says a lot about me then!). I was going to skip over it and then I found this cool little web part – Toolbar Manager . Problem solved!

This neat web part sits on the page like any other, and has a simple set of properties which basically hide any or all of the toolbar buttons (and associated menu items) on a list view web part. It is SO easy to use, and the source code is available to so you can customise it if needed. I have added an extra bit to hide the view selector as well. So now the users can have whatever they want to see on the toolbar, and us developers can stop them doing anything but change the view! My next tweak will be trying to get it to add custom buttons as well. It can’t get much better!! Thanks Scot!! (BTW you can download the source code and/or solution packages from CodePlex)

Si