Convert form to TIF in background process - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Convert form to TIF in background process

Last post 03-29-2012 04:09 PM by tootuff305. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-14-2012 09:41 AM

    Convert form to TIF in background process

    I'm trying to convert all of my completed InfoPath forms in a SharePoint repository to TIF format.  I've already created a console application that runs on a separate utility server to poll the List for certain criteria via SP Web services and am able to convert the file using the Microsoft Office Document Writer with the following code:

     

    public void ConvertFile(string fileName)

    {

    Microsoft.Office.Interop.InfoPath.
    ApplicationClass oApp = new ApplicationClass();

    try

    {

    XDocument oDoc = oApp.XDocuments.Open(fileName, 1);

    oDoc.PrintOut();

    Thread.Sleep(5000);

    }

    catch (Exception ex)

    {

    Utils.WriteToLog(string.Format(@"DataAccess.cs - ConvertFile({0}). Exception: {1}", fileName, ex), Utils.ErrorTypes.Error);throw ex;

    }

    finally

    {

    oApp.Quit(
    true);

    }

    }

     

    I already have the Document Writer configured using Registry settings to output to a designated folder from where I move it to the proper repository in our Records system. 

    I'm kicking off the executeable via Scheduled Tasks on a set schedule which works fine provided someone is logged onto the system.  I have two issues:

    1. If someone logs onto another terminal session, they can affect or hold up the process because the InfoPath form opens up within their session.  How can we have this open up in a background process and still print out? 

    2. Run the code without requiring someone to be logged onto the session.  Even though I run the code with a userid that has rights, the code can grab a form but has issues opening up the template.

     

    Any ideas?

     

  • 03-20-2012 06:02 PM In reply to

    Re: Convert form to TIF in background process

    I was informed that I could possibly run the process in the background by opening the document in a different manner.  I attempted to follow another post i saw to open up the document by swapping out the XDocument oDoc = oApp.XDocuments.Open(fileName,1) with the following code:

    XDocuments oDocs = oApp.XDocuments;
    Type oDocsType = oDocs.GetType();
    object objDocName = fileName;
    XDocument oDoc = (XDocument)oDocsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, oDocs, new Object[] { objDocName, null, null });

     

    Unfortunately, I don't know what the expected parameters are for the InvokeMethod and am getting an exception error stating:

    Number of parameters specified does not match the expected number

     

    Any suggestions?

  • 03-28-2012 10:36 AM In reply to

    Re: Convert form to TIF in background process

    So I found a way to make this run in a background process by turning the applicaiton into a Windows Service and using a Timer Job.  This worked fine in my development environment.  However, I am not getting the following error in Production when running the service.

    The selected file is an update of a form on your computer. However, the update has been blocked because the author of the file cannot be verified.

    I can login to the server using the credentials of the service account that's running the service and it can definitely open up the files from the SharePoint Form library without any issues.  It's almost as if the service account is using an entirely new user profile or none at all when connecting to SharePoint.  It appears to be an issue with Internet Explorer settings.  Does anyone have any suggestions?

  • 03-29-2012 04:09 PM In reply to

    Re: Convert form to TIF in background process

    I found the answer.  Turns out that the system still had a cached template of the one from my dev environment.  Even though i tried the "infopath /cache clearall" while logged in as the account running the service it still kept pointing to the old template.  I ended up doing a search for the physical folder that did the trick.  Make sure to delete out the contents of the following folders:

     - C:\Documents and Settings\Default User\Local Settings\Application Data\Microsoft\InfoPath\FormCache2

    - C:\Documents and Settings\<<serviceaccountuser>>\Local Settings\Application Data\Microsoft\InfoPath\FormCache2

     This is what did it for me.  Now my service runs without opening up the form in the Foreground.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.