May 19

Written by: Michael Washington
5/19/2011 5:34 AM  RssIcon

image

The Document Toolkit for LightSwitch is a commercial LightSwitch control extension. It is one of the first to become available, and is a great example of an extension that allows you to do amazing things easily with LightSwitch.

image

Click here for directions to install the control extension.

The Resume Application

To run the Document Toolkit for LightSwitch through it’s paces, let’s build a LightSwitch application that will allow us to organize resumes. This application will allow us to enter information from job candidates, and upload and store their Microsoft Word resume in the application. The Document Toolkit for LightSwitch will allow us to see the resumes.

image

First we create a new LightSwitch Desktop application.

image

We use the schema above for the table. Notice that WordDocument has a type of Binary.

image

When we create a List and Details screen, we then have the opportunity to change it to use the Document Toolkit for LightSwitch extension.

image

Next, we add a button.

image

Enter the following code for the button:

 

using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using Microsoft.LightSwitch.Threading;
using System.Windows.Controls;
namespace LightSwitchApplication
{
    public partial class ResumeDatasListDetail
    {
        partial void UploadDocument_Execute()
        {
            // Write your code here.
            Dispatchers.Main.Invoke(() =>
            {
                var dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == true)
                {
                    // load document into byte[] (== binary)
                    var data = new byte[dlg.File.Length];
                    using (var stream = dlg.File.OpenRead())
                    {
                        stream.Read(data, 0, data.Length);
                    }
                    // assign loaded document to Document property
                    this.ResumeDatas.SelectedItem.WordDocument = data;
                }
            });
        }
    }
}

 

image

When we run the application, we can add a new person…

image

We can then click the Upload Document button…

image

The document shows up in the Document Viewer (note, it will have a watermark, to remove the watermark, you will need to purchase the product at: http://firstfloorsoftware.com/documenttoolkit).

Click Save to save the record and the document.

16 comment(s) so far...


Gravatar

Re: Using The Document Toolkit for LightSwitch

This is great!

LightSwitch is not even out of beta and there is already a commercial extension available. This is just the beginning and I truely believe that the market for LightSwitch extensions will explode soon.

I can't wait to see what other creative solutions are on their way.

Paul

By Paul Patterson on   5/19/2011 7:17 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Michael,
Thanks.
Do you know if it works both in and out of browser?
paul.

By paul on   5/20/2011 9:19 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

I was only able to get it to work out of browser, but ask on http://firstfloorsoftware.com

By Michael Washington on   5/20/2011 9:20 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Fantastic. My boss has been bugging me to find something like this.

By Garth Henderson on   5/21/2011 8:04 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Thank you for his intellectual contribution

By Luis Mariano Russo on   5/22/2011 2:11 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Thanks Michael. This is great

By Bhuven on   7/3/2011 9:19 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

great tutorial and love the extension

By Dave on   7/24/2011 4:52 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Hi Michael

there is problem with Right to left .

In Arabic Lang mode the Word file also RTL that mean Data appear in reverse

how can fix this please ?

By nasser on   8/22/2011 12:04 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

@nasser - You want to contact http://firstfloorsoftware.com

By Michael Washington on   8/22/2011 12:22 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

What is the VB code to do this??

By Kevin Delaney on   9/21/2011 4:20 AM
Gravatar

Failed to render page.

Hi Michael,

I am getting following errors while trying to upload any document.

for PDF : Failed to railed to load package part "1.fpage"(PDF support is experimental. Document may not be rendered correctly)

for Excel : Document conversion failed - Exception from HRESULT : 0x800A03EC

for Word : Document conversion failed - Exception from HRESULT : 0x800A1066

How to solve it?

Please help...

Thanks,

Vivek

By Vivek Vishwakarma on   11/29/2011 5:43 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

@Vivek Vishwakarma - You will want to report any errors at: http://firstfloorsoftware.com/documenttoolkit

By Michael Washington on   11/29/2011 5:44 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

very great!
Thaks you so much. it's very helpful for me^^

By nguyen cong vinh on   11/8/2012 9:40 AM
Gravatar

Re: Using The Document Toolkit for LightSwitch

Thanks for this however when I try to upload the document it says object reference not set to an instance of an object

By Jason Assaf on   12/3/2014 5:06 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

@Jason Assaf - Please contact the vendor for support. Thank You

By Michael Washington on   12/3/2014 5:06 PM
Gravatar

Re: Using The Document Toolkit for LightSwitch

I found the reason why it was saying that I needed to fill out the rest of the data first. Thanks for the tutorial really helped I just wish it would support pdf

By Jason Assaf on   12/8/2014 9:15 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation