Freigeben über


Programmatically Writing Files to Directories

Ok, so it's easy to send an e-mail, post to a web service or post to a WSS/SPS Form Library using the canned data connections.   That's all fine and well.   It's not easy however to push a file to a file directory, either locally or to a file share somewhere on the intranet.   I had a problem recently where we needed to post an InfoPath XML file somewhere that BizTalk could grab and then do something with it.  Like I said, it's easy to push a file into a form library, and theoretically the form library should be referenceable via a UNC path.  Oddly, the UNC path works fine from a remote machine, but won't work on the server.   Because I have BizTalk and WSS co-located on the same box, I was stuck.   So here are some code samples on how to push files to the file system.     I was under the impression that if you used any code on the submit button, you could *only* use code and not use things like rules and data connections.   Turns out that isn't entirely true, you can't mix rules and code, but you can save time and reference the data connections in code .   These samples require security to be applied to the solution in order for them to work, I set the solution to be full-trust explicitly.

function SubmitMe::OnClick(eventObj)

{

//Hard coded UNC Path.

var strDataCache="\\\\pashllfixit\\siebelfiledrop\\forreporting";

var oTeamMember = XDocument.DOM.selectSingleNode("//my:TeamMember");

var oMonth = XDocument.DOM.selectSingleNode("//my:Month");

var oYear = XDocument.DOM.selectSingleNode("//my:Year");

strDataCache = strDataCache + "\\" + oTeamMember.text + " " + oMonth.text + " " + oYear.text + ".xml";

try {

XDocument.SaveAs(strDataCache);

}

catch (ex)

{

XDocument.UI.Alert("Document submit to file share failed.");

}

XDocument.DataAdapters("Main submit").Submit();

eventObj.ReturnStatus=true;

XDocument.UI.Alert("Your success message here!");

Application.XDocuments.Close(XDocument);

}