Check out my new live search component to the right here ->
I came across this on Heather Solomon's blog, thought it was cool so had a play and set one up for my blog.
To start with get yourself over to http://search.live.com/siteowner, select the advanced option. I think it only works if you have your blog on a custom domain like blog.steveclements.net as www.geekswithblogs.net/steveclements doesn't work. I also created a live search macro for geekwithblogs.net and used and existing one for msdn sites and blogs. Creating your own macro is very straight forward, well the basic one is, I didn't actually look at what the advanced offered.
Here you can see the four tabs for different search results.
The live.com tool generates the code for you, but I had to make a couple of changes to get it to look right (background-color: White, add a search title) and fit (reduced the width).
I am pretty excited about this, I have used google and live search before just to find content on my own blog so this is definitely going to get lots of use, with geekswithblogs on there makes it even more useful, I often remember a post from the geekswithblogs feed, but cant remember who posted it. With MSDN and web makes it pretty complete I reckon!
Heres the code.
To get it to show in the blog paste it into admin settings -> options -> configure -> static news/announcement.
<!-- Live Search -->
<meta name="Search.WLSearchBox" content="1.1, en-GB" />
<div id="WLSearchBoxDiv">
<table cellpadding="0" cellspacing="0" style="width: 185px">
<tr>
<td style="font-weight: bold;padding-right:5px;text-align:left;">Search</td>
</tr>
<tr id="WLSearchBoxPlaceholder" style="background-color:White;">
<td style="width: 100%; border:solid 2px #4B7B9F;border-right-style: none;">
<input id="WLSearchBoxInput" type="text"
value="Loading..."
disabled="disabled"
style="padding:0;background-image: url(http://search.live.com//siteowner/s/siteowner/searchbox_background.png);background-position: right;background-repeat: no-repeat;height: 16px; width: 100%; border:none 0 Transparent" />
</td>
<td style="border:solid 2px #4B7B9F;">
<input id="WLSearchBoxButton" type="image"
src=http://search.live.com//siteowner/s/siteowner/searchbutton_normal.png
align="absBottom" style="padding:0;border-style: none" />
</td>
</tr>
</table>
<script type="text/javascript" charset="utf-8">
var WLSearchBoxConfiguration=
{
"global":{
"serverDNS":"search.live.com",
"market":"en-GB"
},
"appearance":{
"autoHideTopControl":false,
"width":800,
"height":550,
"theme":"Green"
},
"scopes":[
{
"type":"web",
"caption":"Steve Clements",
"searchParam":"site:blog.steveclements.net"
}
,
{
"type":"web",
"caption":"GeekswithBlogs",
"searchParam":"macro:steveclements.geekswithblogs"
}
,
{
"type":"web",
"caption":"MSDN",
"searchParam":"macro:livelabs.msdn"
}
,
{
"type":"web",
"caption":"Web",
"searchParam":""
}
]
}
</script>
<script type="text/javascript" charset="utf-8"
src="http://search.live.com/bootstrap.js?market=en-GB&ServId=SearchBox&ServId=SearchBoxWeb&Callback=WLSearchBoxScriptReady">
</script>
</div>
<!-- Live Search -->
Silverlight makes working with videos pretty straight forward, Microsoft makes Silverlight pretty straight forward with ASP.net and sharepoint is written in ASP.net, so match made in tech heaven!!
I wanted a video player web part for sharepoint, that had some simple functionality like play, pause and volume. I started with expression encoder which output a nice media player interface...this is OK, but has a couple of restrictions; 1, its far to rich for what I wanted, animations all over the place and 2, its JavaScript with Silverlight 1. So, using blend I opened one of the exported files to rip out a few features of the player.
Play / Pause button, volume control and some associated storyboards for some nice animations... visible = true; visible = false is so last year!!!
I copied the xaml into my own Silverlight 2 app, that already had the media player element. A little positioning in blend and we're off. Right that's far too much waffle lets get to it!
I wont paste the xaml here as it basically only a media element, the play/pause button and volume control copied from Expression Encoder. OK, well maybe a little...
<MediaElement HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="MediaMain" VerticalAlignment="Stretch" Source="" Stretch="Fill" AutoPlay="False"/>
What I did add was handlers for all of the events e.g. Play, pause, volume (actually all the code to do the slider) and hide/show events for the play button. More on that in a mo.
Of course for this to be a web part, the movie file at least has to be a variable that's changeable in the properties of the web part. To do this I am going to use Silverlight's InitParams property. Its worth mentioning that the movies are nothing to do with me...they are going to live in a sharepoint library, they are encoded into wmv format using another app.
In the App.xaml file within your Silverlight project you will find an OnStartUp method, this is where I handle the InitParams.
private void OnStartup(object sender, StartupEventArgs e)
{
this.VideoUrl = string.Empty;
if (e.InitParams["videoUrl"] != null) {
this.VideoUrl = e.InitParams["videoUrl"];
}
if (e.InitParams["AutoPlay"] != null) {
this.AutoPlay = Convert.ToBoolean(e.InitParams["AutoPlay"]);
}
else {
this.AutoPlay = false;
}
if (e.InitParams["Loop"] != null) {
this.Loop = Convert.ToBoolean(e.InitParams["Loop"]);
}
else {
this.Loop = false;
}
// Load the main control here
this.RootVisual = new Page();
}
As you can see I am expecting 3 params and set class level properties for later use. AutoPlay(play the video on page load) and Loop play(to obvious to describe!!), VideoUrl (the url of the video to show).
public string VideoUrl { get; private set; }
public bool AutoPlay { get; private set; }
public bool Loop { get; private set; }
In the Silverlight class (Page) constructor I get the values like this...
App currApp;
public Page()
{
// Required to initialize variables
InitializeComponent();
currApp = Application.Current as App;
VideoMain.Source = new Uri(currApp.VideoUrl);
VideoMain.AutoPlay = currApp.AutoPlay;
if (currApp.AutoPlay) {
ControlsPlayPause.Opacity = 0;
PlaySymbol.Opacity = 0;
PauseSymbol.Opacity = 1;
}
Here you can see I get the current application, cast it as App (insert whatever the name of your own application class is...App is default) and access the properties. I am setting the source of the video and deciding whether to play or not, setting the UI to suit.
I have a couple of handlers on the UserControl to show the play/pause button. Basically when the mouse hovers over the control show the button (begin the StoryBoard that animates it in)
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
if (ControlsPlayPause.Opacity < 1)
PlayPause_Show.Begin();
}
private void UserControl_MouseLeave(object sender, MouseEventArgs e)
{
PlayPause_Hide.Begin();
}
In the top one, I check for opacity, as you can see in the class constructor if the video is not set to AutoPlay I show the play button.
I don't use this, but for reference this is what the markup would look like to use this Silverlight app.
<div id="silverlightControlHost">
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">
<param name="source" value="ClientBin/VideoViewer.xap"/>
<param name="background" value="white" />
<param name="initParams" value="videoUrl=http://mossinstance/site/library/movie.wmv,AutoPlay=true,Loop=false" />
<a href="http://Silverlight.2.0.exe" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
-----------------------------------------
Now onto the web part. I am going to have the Silverlight app on the Sharepoint server, there are obviously several ways, one that appeals to me most is have a sharepoint library for your Silverlight apps, or it could be as simply as creating a ClientBin folder at the route of the site. Don't forget you need to set the MIME type up for Silverlight.
The web part itself is pretty simple, all I need is 3 properties, create the Silverlight control and set the InitParams.
I do have a custom "NotInstalled" template, but you don't need that. I didn't want users to have to download the installer from the web, so I have put it on the network. You will also see I have set the source of the Silverlight control to a ClientBin folder at the root of the site.
Another point to note(!) I have put the dll System.Web.Silverlight in the GAC, there are arguments for and against, I prefer the GAC.
Now install your web part in whatever method you prefer...
Some pages/sites/articles that helped.
I have literally just found this on codeplex, it's a Silverlight 1.0 video player web part for Sharepoint. Would have been no good for me as I have no interest in Silverlight 1.0, but you might!!
The more I work and develop with SharePoint I am learning that 95% of the task, with a little guidance is a walk in the park, especially when compared to that final 5%, which is either impossible or is the most painfully experience any developer can experience!!
Take my Friday hell for an example...
A requirement comes in for custom news item, with a property that is the users department, but could be changed to another. Sure i think, drop down control, bind to all the possible departments, auto select the user department, getting the value from the users profile.
Converting that into SharePoint, create a custom field, inherit from SPFieldChoice, bind to an SPList with all the groups (add to the base.Choices collection), get the current user from the SPContext, use that to the query the users profile to get the department, set the base.DefaultValue. Cool, now that is sweet, test in a simple column adding to a list, works a treat. The field is wanted for a page content type though so...
Create a site column, add to content type, create custom page layout, drop on...we are rocking so far.
Go to create a page and my group is selected, awesome. Change my group just to test, but nope still selects old group...hmmm...iisreset....nope the same. Test with other users, the same!! Just to confirm, its not selecting the first item in the list, its selecting the department of the admin user who deployed the solution, and what it was when they deployed it!!!!! Now that is nuts, go into a standard list, works a treat!! After hours of thrashing, trying to add it directly as a column to the page library and many others i gave up and came up with a far less appealing solution but a solution none the less....so what the feck is going on here???
Its worth noting that i put some trace code in and found that the correct department was being pulled through, and checking what base.DefaultValue was after setting it showed it was what I expected, but on the page was the admin's original group. If anyone else has experienced similar it would be great to here from you, I can post some code if you like, but its pretty simple stuff and like i said, works in standard items.
I did actually take the time this weekend to create a custom field rendering my own drop down list, the value is auto selected as I would expect, but I the value doesn't display in the "View Properties" or "Published Page" mode, fine in "List View"....its metal!
P.S. I have another one to with sub classing the CQWP, that I might post later.
I mentioned a while back that I had something I was working on that involved a change in language, actually a pretty radical change. I have been working on vocational project written in VB.net and made heavy use of LINQ to SQL. I wasn't sure of LINQ to SQL for anything else other than RAD and to be honest I'm still not. Anyway, I'm not getting into that debate. Needless to say I went all the way and don't use a single sproc in this project.
Some of you will know I play cricket every Saturday for a local club (nothing special, just for fun!), well for a couple of years I have been thinking of putting a website together for the club, just never got round to it. However the other day I was looking at the starter kits on the asp.net website and came across The ClubSite v2.0, also hosted on codeplex, basically this is built on top of the original ClubSite, it adds functionality and has layered the code. Problem is, its American and the statistics part of the site relates in no way to cricket, which is a pretty statistics intensive sport.
I decided to write the cricket stats engine (that sounds fancy!), and take the opportunity to write some real code in VB.net and LINQ to SQL. I have pretty much completed this project on my train journey to and from work, which is about 40 mins each way. Working on it not every day, but most for the past month.
The original ClubSite makes use of submodal for its AJAX functionality and some modal popups, I am not really a fan of these and found them to work erratically so have replaced a few and plan to do the rest, using the asp.net AJAX control toolkit modal popup. I have also added update panels to make the UI some what slicker! I code is in no way of a work of art, that's not really been the point of the exercise.
I haven't finished the project, apart from very limited testing, I plan on using silverlight (to tick another "must learn more about" box) to create some pie charts etc to better represent the data. I have actually found some open source examples i intend to download soon.
I appreciate that cricket is a pretty captive audience and cricket playing geeks are no doubt even less, but hopefully I will get some downloads and help if finding bugs and enhancing the project. I have actually only found 1 other site that does cricket statistics and that is a national site and every club has a sub-site within the main site. Far to restrictive for my liking.
Go and check the project out here: Cricket Club Starter Kit
It's also worth mentioning that I haven't changed any of the original ClubSite v2.0 code, I have simply added on to it, mainly because I don't to miss out on anything that gets released/fixed with that project. Apart from perhaps a link of two in the menu to point to my new CricketStats folder and the graphic from a football (soccer ball) to a cricket related image. I haven't even fixed bugs that I have come across, that isn't the point of this project. On Codeplex I have checked all the code in, including scripts to create the schema in the db, but not all my test data (yet). I'm not sure if this is the best way to go about it, it might be better to simply check in the new code and some scripts to incorporate it in into the clubsite v2.0. That might over complicate the whole development process though.
A Few screen shots to give you a flavour!
Games in season overview - (Default.aspx)

Game Statistics

Team Statistics for the season

Player Statistics by season

ADDING AND INSERTING DATA


Now that is a bad ass title!!
Anyone who has been through the MindSharp training course for SharePoint and any others that have looked at any code Todd Bleeker puts out there will most certainly be aware of using post build scripts in Visual Studio to deploy your sharepoint project. This knowledge is of course not limited to MindSharp grads, its just that being one I know what they know!
To get them to work in a Windows 2008 and Visual Studio 2008 environment you will need to make some changes. As pointed out here, GacUtil has moved so the command will change from
this
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe" /if "$(TargetPath)" /nologo
to this
"%programfiles%\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe" /if "$(TargetPath)" /nologo
...and the command to recycle the app pool in IIS7 has changed, if you try the old way you will most likely get a Microsoft.CmdLib error when building from VS. The required command has changed from
this
"%systemroot%\system32\iisapp.vbs" /a "[YourAppPool]" /r
to this
"%systemroot%\system32\inetsrv\APPCMD" recycle apppools "[App Pool Name]"
This is as much for me as everyone else as I no doubt will come up against this again!
For completeness here is my postbuild script for a custom field project, you might not want to copy the debug pdb file or create a solution (last two commands)
cd "$(ProjectDir)"
"%programfiles%\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe" /if "$(TargetPath)" /nologo
"%systemroot%\system32\inetsrv\APPCMD" recycle apppools "App Pool Name"
xcopy "TEMPLATE" "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\" /ys
xcopy "$(TargetDir)*.pdb" "%systemroot%\Assembly\GAC_MSIL\OC.Sharepoint.FieldTypes\1.0.0.0__[token]\" /ys
MakeCab.exe /f FileName.ddf
My first trip to the new Wembley stadium was to watch the Foo Fighters gig on Saturday night, who as far as I am concerned are the best band on the planet right now. They did well to beat Oasis to that accolade, but heh, Oasis haven't done anything for quite a while now!! For those that don't know Wembley is a 90K seater stadium in London and the Foo's sold out in about 15 mins back in December, typical to big show form they promptly announced a second night (which was Friday), and that promptly sold out :)
The show was pretty awesome, I was quite a way back in the stands, but was directly in front of the stage so had a pretty good view. I don't have a great camera or indeed an eye for a good shot, but here are a couple of photo's.
Led Zeppelin came on at the end to play Rock and Roll and Ramble On, Dave Grohl declared it as the best day of his life, I had fun, but not that much!
The Carlsberg one was taken by the missus, a birthday present idea perhaps! ;-)

LINQ goes so much further than just SQL and XML.
Something like this is just why I love LINQ, a LINQ query on an ASP.NET ListView controls items.
1: Dim items = From lvi In AspNetListViewControl.Items _
2: Where CType(lvi.FindControl("DropDownList1"),
DropDownList).SelectedValue = someIntVar _
3: Select lvi)
Getting a ListViewItem's where the selected value of a DropDownList is set to the value I want. So simple, yet so powerful.
The observant among you will notice that this is in VB.net, not my native C#!! More on that soon! :)
Technorati Tags:
LINQ,
ListView

Although new to all this MOSS stuff I am getting stuck in with the Content Query Web Part (CQWP) and XSL. They are a pretty powerful combination, but pretty soon I could see how this could become slightly wild and considering ListStyles.xsl is an "out of the box" file, getting crazy with custom files could become more of a problem than simply a huge file.
Check out these two posts on how to manage custom styles.
1. Liam (Sharepoint MVP here in the UK) posts about editing the ListStyles.xsl, but only to add import statements to your own custom csl files.
2. Brendon Swartz post about how to create a new CQWP instance by exporting the default one, editing the webparts xml definition by adding a statement to reference your custom xsl file.
I guess it comes down to whether you are happy, or even able to edit the ListStyles.xsl file, number 1 is certainly the easiest route and my choice, but I can see value in having a CQWP instance for each style. I certainly am no fan of big changes in OOTB files, granularity is good :)
Technorati Tags:
MOSS,
CQWP,
XSL
As errors go I found this one is pretty horrific.
I got the error deploying a windows service written in .net 3.5 from my Vista x86 dev rig, to a 2003 x86 server. Only having the .NET runtime installed on the server I wrapped the service up in a deployment project. The service installed fine, however when trying to start the service I got a "The service did not respond in a timely manner" error. Initially, like you would, I thought there was probably an error with my code in the OnStart method, but alas nothing in my beautifully crafted exception logging framework(!), over to the event viewer and this little beauty!
The complete error is...
EventType clr20r3, P1 <servicename.exe>, P2 1.0.0.0, P3 4816d837, P4 system, P5 2.0.0.0, P6 471ebf0d, P7 36d5, P8 7f, P9 system.argumentexception, P10 NIL.
The error is titled...
.NET 2.0 Runtime error. (Which through me a little, I'm on .net 3.5!!)
After some intense googling I have pretty much "Jack", no clear answer from the MS forums, despite input from MSFT staff. Something that kept popping up was that I was referencing something in the framework that wasn't installed on the server. So I checked every reference manually on the server, I even thought there might be a problem because some of the .NET dll's on my machine are in "/ProgramFiles (x86)/...." the server not being x64 didn't have this folder so, I created it! (Not convinced, but worth a shot!) Nope, same error.
Right, most who have seen this error report no problem on their dev machine with VS installed and get it on machines with just the runtime installed. So, feck it, I installed VS 2008 on the server (clutching right!), I just though perhaps there was something VS installed that I was referencing somewhere...at the very least I would have debug tools installed, speed up the process and could rule it out. Nope, same error. Now I can't actually attach a debugger to the process can I, as the service hasn't won't start!
This is mental! As far as I was concerned I had nowhere else to go. By the way, somewhere in there I actually tried to run the service on a different x64 2003 server, but still the same error. I got another service I have been working on, hacked it about so it would build and run (making sure I was referencing the same libraries as original project). Same drill, wrapped it in an installer, spun it up on the server, started first time!!! Right, nothing to do with the framework, clearly the issue is local to my project.
I created a new project and copied in any custom classes and basically replicated exactly what the problem service was doing, IT WORKED. The only thing different, when I created the first project, I deleted the "Service1" that the project template creates.
If you have made it this far down the post in anticipation of the first cause and "concrete" solution for this error, I am sorry to disappoint, but all I have is it to create a new project and start again...VS must be doing/wanting something weird in the background. After wasting a hours on this I don't have the inclination of patience to look further/deeper.
Perhaps someone has had similar experiences with the error and could enlighten the rest of us?