Compartir a través de


How to Enqueue Submits While Offline

How to Enqueue Submits While Offline

Applies to: Microsoft Office InfoPath 2003 SP1

Scenario:

User fills out forms for a particular form template while the laptop is disconnected from the network. Upon reconnection, seamlessly syncrhonize the offline forms to a Windows SharePoint Services form library.

Solution:

Using OnSubmitRequest, you can have the code save to the offline folder depending on if we're offline or not, as in the following code, which is written in C# using our Visual Studio .NET Toolkit. You will also need to add a project reference to System.Xml.dll and the using System.XML; directive to your form code.

  public void OnSubmitRequest(DocReturnEvent e)

  {

    if (thisApplication.MachineOnlineState == XdMachineOnlineState.Online)

    {

     // submit to Sharepoint using DAVAdapter

     (thisXDocument.DataAdapters["Submit to Sharepoint"] as DAVAdapter).Submit();

    }

    else

    {

     // We are offline or working offline.

     XmlDocument oDOM = new XmlDocument();

     Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument oWrappedDOM = thisXDocument.DOM;

 

     oDOM.PreserveWhitespace = true;

     oDOM.LoadXml(oWrappedDOM.xml);

     oDOM.Save("C:\Submit\Form_"

            + DateTime.Now.ToString("yyyy.MM.dd_HH.mm.ss.ff") + ".xml");

    }

  

    e.ReturnStatus = true;

  }

Then, if you've been offline for a while and a number of files have built up, you can run the following jscript to invoke InfoPath externally and force a submit looping through the files, as below:

var oFileSys = new ActiveXObject("Scripting.FileSystemObject");

var oSubmitDir = oFileSys.GetFolder("C:\Submit");

var oFilesInSubmitDir = new Enumerator(oSubmitDir.Files);

 

var oApp = new ActiveXObject("InfoPath.Application");

 

var fso = new ActiveXObject("Scripting.FileSystemObject");

 

for (; !oFilesInSubmitDir.atEnd(); oFilesInSubmitDir.moveNext())

{

 var strFileName = oFilesInSubmitDir.item().Name.toLowerCase();

 

 if (strFileName.length >= 4

     && strFileName.lastIndexOf(".xml") == (strFileName.length - 4))

 {

  try

  {

   var oDoc = oApp.XDocuments.Open(oFilesInSubmitDir.item().Path);

   oDoc.Submit();

   oDoc.View.Window.Close();

   

   var f = fso.GetFile(oFilesInSubmitDir.item().Path);

   f.Delete();

 

  }

  catch (e)

  {

   WScript.echo("ERROR: " + e.description);

  }

 }

}

oApp.Quit();

Comments

  • Anonymous
    March 17, 2004
    ??????? InfoPath ?????????

  • Anonymous
    March 19, 2004
    Tried your code and it works great...but...when I close the form, it doesn't prompt me to save the changes when the form data has been changed (i.e. dirty).

    Do you know if there is another event to check to see if the form is dirty before exiting?

    Thanks

  • Anonymous
    March 19, 2004
    The document dirty state can be read from the XDocument.IsDirty property. This property can be programmatically set with the XDocument.SetDirty(boolean) method.

  • Anonymous
    April 05, 2004
    Is there a way to use a web service as a secondary data source, and then when disconnected, use a cached version of the data that was available when the form was received?

  • Anonymous
    April 09, 2004
    I have the same need for using offline cached secondary data sources. I am interested in a response to Christoper's question.

  • Anonymous
    April 13, 2004
    Rob / Christopher - We don't have a sample readily available that we can post for that (but we'll consider that for future versions). In the meantime, please try asking the newsgroup (http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.infopath )

  • Anonymous
    April 21, 2004
    I wrote an aspx page that responds with simple XML documents. I then set up a secondary data source that "reads" the aspx file via a URL. It worked! Not only that, I can pass query string elements, and the data that is downloaded is somehow remembered by Infopath when the system is offline. I believe the secondary data source is stored in the temporary internet files, because clearing this folder kills the Infopath template cache and the copy of the SDS data.

  • Anonymous
    October 24, 2011
    I can't for the life of me get this to work with InfoPath 2010. Could anyone provide a tutorial or short walkthrough? Thanks in advance.

  • Anonymous
    October 26, 2011
    The comment has been removed

  • Anonymous
    December 21, 2011
    Hi can the same code be used in infopath 2007.

  • Anonymous
    December 22, 2011
    Hi Heerachand, The only way this will work in InfoPath 2007 and later is if you change the code to be InfoPath 2003 Compatible. The object model changed with 2007 so if you want to use the later object model you will need to re-write this code using the new methods, properties, etc. Scott