Monday, March 21, 2011

Trigger a Scanner using a button in InfoPath form - C#

As I have mentioned in one of my previous post I was spending some quality time with a scanning requirement. Requirement is simple, which is in a SharePoint form there should be separate buttons for scanning multiple documents. There are a lot of plugins  for SharePoint that can trigger a scanner and the most funniest thing is they only provides a limited functionality. And that is, first we should insert a item and then select the item and do the scanning. We can scan multiple documents and the same time it attaches them to the item. (people who might not familiar with SharePoint, might not understand what i told above about the scanning plugins for SharePoint).

But my requirement was not that. The form should have multiple buttons for trigger the scanner. Finally I planned to do some programming with InfoPath and somehow getting my thing done. Finally I have managed to develop multiple buttons to do multiple scanning and attaching to the same document same time, but of course it has some boundaries. I will explain the boundaries later in my post.

I have used Windows Image Acquisition Library 2.0 which can be downloaded for free from Microsoft. It has nice capabilities as well as some limitations. The one of the main limitations is Windows Image Acquisition Library is used for mainly capturing images from imaging devices such as scanners and cameras. So from what I have done, i was only able to get the output of the scanned documents as image type outputs such as JPEG, PNG etc. And the other main limitation is, it does not provide multi page scanning and the reason behind that is again WIA is used for mainly capturing images.

If I talk about the main boundaries of my scanning requirement development, first one is InfoPath form should be uploaded as a form template and should be set to open in the Client Application. The reason for this is if we enabled the InfoPath form to open in the browser, that means the InfoPath form is running on the Server. But the Client machine does not allow the Server to communicate with the Client machine's ports which simply means we cant trigger the scanner. So the InfoPath form should be opened in the Client machine. The other boundary is with the WIA, which is what I have explained above.

I am thinking and doing some things to overcome these boundaries. My solution for communicating with the Client machine from the Server is developing a service or a Client application which is fully separated from the Server and forget about the InfoPath form. Then design a form as a Visual Web Part using Visual Studio and deploy it to the Server. And then using a javascript or a vbscript, trying to communicate with the service or the Client Application, which is so far some what successful.

And for the second boundary, still I have not tried anything. I thing for that either I will have to convert JPEG/PNG into PDF file and add the functionality to add multiple pages to a single document, which seems pretty hard. So I think I might have to change my track into TWAIN scanning.

Will update all of you as soon as I have manage to overcome these boundaries. But I am fully happy with what I have done, because I am not using any of the plugins which you will have to buy to use it.

Happy Coding.

Regards,
Jaliya

6 comments:

  1. Is it possible to explain more and if possible with video

    ayymn@yahoo.com

    ReplyDelete
  2. Is it possible to explain more with video
    ayymn@yahoo.com

    ReplyDelete
  3. you explained excatly what i need... if you did all you mention in the blog you must be the one ... however you just write what did you do, is there any sample code or something can help us to do ourself?

    in my form i have button to scan document but i have system.securityException, can you help me if it is possible ?!

    thanks in advance,
    Mahir KARABACAK

    ReplyDelete
    Replies
    1. Hi Mahir,

      Thank you for your nice comment. Yes, I have developed it and it was like one year back. Currently I don't have the source, but I am sure it should be there in my laptop.

      The thing you must notice is, you will have to set the property to open the InfoPath form in the client machine. I have used WIA, it was working properly.

      I will find the source and let you know.

      Happy Coding.

      Regards,
      Jaliya

      Delete
    2. Hi Jaliya I am Chiranthaka from Sri Lanka. Could you please post that source code that you have developed, because I also tried to develop that and it was stuck due to an error. Because I have used SharePoint web parts. But when I used C# it works perfectly. I only have the error when I am using SharePoint 2010 web parts. My solution is as a link https://drive.google.com/file/d/0B7Hii9aqsRAkN0J1dHRYWGpWOVE/edit?usp=sharing

      Delete
  4. Hi Jaliya, thanks so much for sharing you precious knowledge! I am a dotnet beginner and must say thank you for your kind help!

    ReplyDelete