Closing SharePoint 2010 wait dialog with JavaScript

There’s one nice feature of the SharePoint 2010 UI framework which lets you display a wait dialog with no close button:

SP.UI.ModalDialog.showWaitScreenWithNoClose('Please wait ...', 'Please wait while we process your request ...', 80, 400);

You may want to run this on client click of a button, which ultimately posts back the page.  In my case it was a dialog which did some processing, then ultimately closed.
If you call the above function, and the page posts back, when it returns the wait dialog will still be there… it won’t go away!

Okay, so you say – it should be as simple as calling window.frameworkElement.commitPopup(); … negative, this does NOT work for the above dialog (because likely when you’re executing this, you’re executing it on the main window, not the wait dialog’s frame, which renders this call useless.. and in most cases if you have other SPDialog’s open, it will close THEM, but not the wait dialog.

ANYHOW… JQuery to the rescue: Here’s the fix…
Simply hook a document.ready on the page which is posting back, and manually hide the Dialog and overlay, by doing the following:

$(document).ready(function () {
    ExecuteOrDelayUntilScriptLoaded(function () {
       // UPDATE: Original post I had this executing in the current frame, I change this now to execute on the top frame, otherwise it can't find the dialog
        if (($(top.window.document).find('.ms-dlgContent')).length > 1) {
            $(($(top.window.document).find('.ms-dlgOverlay'))).css('display', 'none');
            $($(top.window.document).find('.ms-dlgContent')[1]).remove();
        }}, "sp.js");
    // Demand the loading of the SP.js script (demand ribbon, which cascades into sp.js and a few other required items such as sp.dialog.js)
    SP.SOD.executeFunc('ribbon', null, function () {});

This will search for all spinner images within the currently open dialogs, and return the last element found (which is generally always the top level dialog – the wait dialog.). It then searches upward for the closest dialog frame, then hides it with a bit of CSS magic. You could probably search upward for the frame element and perhaps close it, but this suited what I needed to do perfectly, because the page will post back soon enough and it will be gone anyway.

jQuery document ready not firing with ajax update panels

The scenario is:

1. You’ve got an update on a page, and you have some jQuery executing a document.ready event.
2. The event isn’t firing when your update panel posts back asynchronously.

The solution is quite easy, take your original document.ready script and wrap it in a function and place it outside of your update panel (linked js file is fine):
function BindLoadEvents() { $(document).ready(function() { alert(‘fired!’); }); }

The bold text was the body of your original function.

Now, inside your update panel (preferably at the top):
<ContentTemplate>
<script type=”text/javascript”> if(typeof BindLoadEvents == ‘function’) Sys.Application.add_load(BindLoadEvents); </script>

Now, your script will execute when ajax has finished loading the page, including when new postbacks are made within your update panel!

Note that I have noticed slight flickering on the first request, to get around this, you can inline a call to BindLoadEvents(); within your <script> which sits outside of the update panel (below the BindLoadEvents function def), this will cause it to execute twice though, but the first time will be executed as the page renders, vs waiting for the page to finish loading, hence removing the slight delay.).  Let me know if there’s a nicer way to fix this glitch.

 

Feature could not be installed because the loading of event receiver assembly X failed:

The problem is, when you’re in visual studio debugging a feature receiver, and you have your build actions set to ‘Default’ (ie, not No-Activation), it will deploy the solution, then try and activate your feature (which has your event receiver in it (which probably deploys an SPTimerJob or something similar)).  You get the error saying that it cant find your assembly.  BS!  It’s in the GAC!  I can see it, and it’s the right version??

I’ve just been banging my head against the brick wall with this one.
I came across the following article.

But unfortunately it didn’t help me out, the comment someone left in there about using -force was interesting, but I need this to work within VS… if I just use powershell, it activates fine.

The quick and (maybe a little bit dirty) solution for me (without needing to create and move a bucket load of code into a new project), is simple:  Bump the version number on the assembly that contains your event receiver (read: the assembly you’re deploying to the GAC).  Go into the assemblyInfo manifest, and update the version from 1.0.0.0 to 1.0.0.1, then redeploy.  Violla… the problem will go away (or at least, it did for me).

Second to this, you’ll notice then that all references to the Strong Name of that assembly then need to be updated.  If you’re referencing it in user controls and so forth, take a look at replacing the Version= component of the strong name with: Version=$SharePoint.Project.AssemblyVersion$

The sharepoint project system in VS will replace this macro with the current assembly version, saving you having to update it each time when you change it (when you get this error, for instance :) ).

All web part pages will need to be updated as well, (ie web parts need to be reimported, because the version changed).  Do it once, and you shouldn’t see it again (not sure what originally caused it… but for me, it was after a reboot! Random.).

Enjoy!

UPDATE:
Earlier this week I found myself delving deep into the realms of timer jobs, and found that the SharePoint Timer Service loves to cache assemblies (Objects table in sp config).  I received this same error today.  Using my knew found knowledge as a premise, I retracted my solution in VS, I then restarted the SPTimerV4 service,  then redeployed the solution – the features now activate.  I think the reason it can’t find the assembly is something to do with it using an older cached version of the assembly, and because (correct me if I’m wrong) that feature activation is run through the timer service, this some how relates to it not being able to find the assembly.

 

How to install Windows 8 side by side with Windows 7 the easy way!!

I have been trying many different ways to get windows 8 installed… I have been trying to find the least ‘intrusive’ way that I can.

I just wrote an entire write up on how to do this.  But wordpress deleted it.  Thanks word press for wasting an hour of my time, and hard work.

In order to do this, simply read this.

If you want to boot from a VHD on an external hard drive, read this.

Thanks again, WP.

 

 

 

 

 

 

 

 

 

 

 

 

Windows 8

So if you’re been living under a rock for the last day or so (OK, fair enough, this is pretty fresh news, I don’t blame you).  Then you’d know that Windows 8 Developer Preview has been released!
I thought I would take this opportunity to share with you some of the content that I’ve reviewed and gathered with regards to Windows 8, to save you a bit of time trawling through the interwebs.

Before I continue though, you’re probably wondering where to get it:

There’s 3 skews you can download:

1. Windows Developer Preview with Developer Tools (English), x64
2. Windows Developer Preview English, 64-bit (x64)
3. Windows Developer Preview English, 32-bit (x86)

The main difference between the 2 types here (tools/no tools), is that the first on the list contains all of the tools (SDKS, etc) to develop on the new Windows 2008 platform, you also can’t perform an in-place upgrade of your pre-existing operating system using this version, in order to do an upgrade you need to use the last 2 in the list (not that I would suggest doing this on your favorite box just yet!).

Interesting Resources / Videos:

1. Build hardware overview video
2.  Windows Developer Preview Technologies
3.  BUILD Keynote
4. Walkthrough of the new Windows 8 User Interface
5. Smarter file copying in Windows 8
6. Mango apps now being accepted on the Market Place!

If you have any other cool links, please feel free to share them and I’ll add them to the list!
I’ll keep adding them as I come across them.

Binding WPF DataGrid ComboBoxColumn to view model data source

In Silverlight, you would generally create a DataContextProxy for this issue.  However, in WPF we need to do things slightly differently:

 <DataGridComboBoxColumn Header="Staff Member" Width="*">
                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Staff}" />
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>
                </DataGridComboBoxColumn>

So, to break this down – we are essentially creating a new style for the editing template, and targeting the internal combobox which is created as part of the data grid column.
We then need to set its ItemsSource to our binding expression. We need to do this because the datagrid cells do not form part of the visual tree, therefore we can’t apply
binding expressions to the ItemsSource on the combobox, as it doesn’t have a DataContext.
The actual binding expression is pretty neat as well, we basically use a RelativeSource, and tell it to use the FindAncestor mode with a type of ‘Window’, which will look for the first ‘Window’
type in the parent heirarchy, and use that as the source. We can then bind to the DataContext on that window object (which we are setting as our ViewModel, in the constructor of our Page.) In
this example, our view model has an ObservableCollection of Staff objects that we are binding our list to.

System Interface Mockups

Lately, I have been pushed more and more into needing a better way at mocking up systems.

Today, I came across Balsamiq and I have to say, I am very impressed!

This tool makes mocking so simple.  Within minutes I was able to mock up a system across a number of screens, and it’s friendly on the eyes for the end-users.

+1 from me.

Agile Architecture

I came across this fantastic article which details how agile fits in with architecture in small to large projects:
http://www.agilemodeling.com/essays/agileArchitecture.htm#Who

Key take-aways:

1. Beware of Ivory Architects/Architectures.   People often spend too much time building the perfect architecture instead of proving it, and revising it based on ‘real’ testing.

2. In small teams, assign an Architecture Owner role.  Don’t get into a situation where you have one person who owns everything (Aka, ‘The architecture becomes their baby’), because no one likes being told their baby is ugly.  Use a team approach, and get everyone involved.

3. They ain’t ganna read it (TAGRI).  Travel light, and don’t write a 50 page document for the sake of it.  It simply won’t get read, and it probably isn’t going to help anyone.  Be more interactive, save key discussions and models, but don’t bother with anything this large.

4. Prove your architecture.  Some overlap here, but essentially the idea is that you prioritize the parts of your architecture which you think may be more important/hard to implement, then allocate some time to prototype and prove it before going ahead, because if these important underpinnings don’t work, chances are you’ve wasted a lot of time and will be up for a fair amount of rework later down the track.

 

Bunch more, but I will leave it at that – go have a read!

Matthew Cosier

When to use SQL Server Merge Replication VS Sync Services for compact disconnected applications

Recently I’ve been asking the question of why I would bother using Sync Services when I could very well just set up merge replication inside SQL Server + SQL Server CE 4.0.

Here’s a great article I found which outlines the reasons why you might want to choose one over the other:
http://blogs.msdn.com/b/sqlservercompact/archive/2009/11/09/merge-replication-vs-sync-services-for-compact.aspx

It’s evident that you would consider using Sync Services when you wanted more flexibility over the transport channel, and overall sync use case.  Where as merge replication is much  more targeted towards enterprise integrations.

I will try both :)

M

How to remotely play songs on your Xbox

I’d love to be sitting at my PC right now, and have the ability to swap and change my songs that are playing on my home theatre on my Xbox.

Here’s how:

http://jeffrey-parker.com/blog/fuze/remote-control-xbox-360-music-using-a-cell-phone-or-pc/

Steps:

1. Install TVersity

2. Install Winamp

2. Create an m3u file (described above) which points to your instance of Winamp (port 8000 by default?)

3. Serve the file to your xbox using TVersity (you can probably do this with standard media centre too (not tested)).

4. As the m3u plays, it should be streaming down whatever you’re playing in Winamp to your xbox.  Simply queue up your tracks, and you’re done.

Thanks for the blog post Jeffrey.

Matthew Cosier