How to Enqueue Submits While Offline


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:SubmitForm_"

+ 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();