Using Control in Lightswitch

Nov 9, 2011 at 2:43 PM

Hey Developers,

I like your control - great work! I would love to use it in MS Lightswtich applications.

The following code ...

UploadFileDialog dialog = new UploadFileDialog();

throws an Exception in LightSwitch :-(

The Problem seems to be the following: ChildWindow (from which UploadFileDialog is derived) does not work in Lightswitch!

Is there a way to still use your control (maybe without a popup window)?


- Simon

Nov 9, 2011 at 2:55 PM

Thanks for the kind words, we appreciate the feedback. In regards to LightSwitch, we have not tested with that product suite. Gives us some time to evaluate the integration process, and we will get back to you.

If you have a code sample of how you integrated and are attempting to use, would help as well.


Nov 16, 2011 at 10:32 AM

It is easy to reproduce my Error:

(1) Just create a new LightSwitch Application.
(2) Add a button to a screen
(3) In the button's click-handler add: UploadFileDialog dialog = new UploadFileDialog();
(4) This code will throw a runtime exception

The reason for the exception seems to be, that ChildWindow is not supported in LightSwitch. Is there a possibility to use your code without using the ChildWindow-Control?

Nov 16, 2011 at 5:04 PM

The ChildWindow is the control.

Nov 16, 2011 at 5:30 PM

I just installed LightSwitch, and the error I get is invalid cross-thread exception

Nov 16, 2011 at 6:04 PM

I can get the dialog to work, just trying to figure out how to setup the server side.

Nov 16, 2011 at 6:48 PM

OK, got it to work!

First the Client Side:

1. You have to add a reference to the HSS Interlink (which you've already done :) )
2. You have to add a reference to System.Windows.Controls
3. LightSwitch has a custom dispatcher process so it gets a little hacky, but do this: (note: i didn't play with all the different ways this could work, but this one particular way does)

System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
				d = new HSS.Interlink.UploadFileDialog();
				d.Completed += new EventHandler<HSS.Interlink.UploadCompletedEventArgs>(d_Completed);
				Microsoft.LightSwitch.Threading.Dispatchers.Current.BeginInvoke(() =>
Now the Server Side
1. Add a reference to the HSS.Interlink.Web dll
2. Implement your UploadHandler (I just copied directly from the TestClient.Web from source control)
3. Find your web.config file. Mine was here (..\Application1\Application1\ServerGenerated) and add the appropriate entries
<!-- App Settings -->
<add key="UploadHandler" value="LightSwitchApplication.UploadHandler, Application.Server"/>

  <add verb="GET" path="trace.axd" type="Microsoft.LightSwitch.WebHost.Implementation.TraceHandler,Microsoft.LightSwitch.Server.Internal,Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  <add verb="GET,POST" path="FileDownload.ashx" type="HSS.Interlink.Web.FileDownload, HSS.Interlink.Web" />
  <add verb="GET,POST" path="FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" />

Build and run and it should work.
Let me know how it goes?
Nov 16, 2011 at 8:30 PM

Also, blogged about this here

Nov 17, 2011 at 3:56 PM

Wow - your help is absolutly amazing! Thank you so much.
I will read your blog post and try it in my LS Application and then post my feedback here.

Once again, thank you for your absolutly amazing support!!!

- Simon

Nov 17, 2011 at 5:14 PM

Thanks for the kind words, we appreciate the feedback!

Nov 21, 2011 at 2:57 PM

I read your blog post and codeproject article. You did a great job figuring out how to use the right Dispatcher. It already works in my test environment and I will test it in an published application soon. Thank you again for your super-fast support and for the helpful tutorial!

- Simon

Feb 21, 2013 at 1:48 AM
Hello, i think this example does not work in the HSS Interlink v.3 , i didn't find UploadFileDialog; could you help us by upgrating this example, i have tried with UploadControl but i don't know how to open the dialog , so i will try with UploadCliente, i am reading the new funtions.

Thank in advance for you amazing work!
Feb 26, 2013 at 8:55 PM
You'd be correct. The changes in v3 will break the example. We will try and get around to updating the sample LS code.
Feb 26, 2013 at 11:58 PM
i already made something to get it working, in my machine it works perfectly but when i publish it, i got an error somethink like "The remote server returned an error: NotFound." i think the problem around public static string FileStoreFolder = @"Interlink\Uploads"; so i exchange it for my folder. I really dont know what is happening, my app is not in root directory. Thanks for your reply!