Hi all! I'm new with InfoPath and I'm not a programmer or anything so I basically spend hours on forums while doing my InfoPath file... I'm also French, all that means that, I need easy English answers and step-by-step instructions with coding because I'm learning.
I'm using InfoPath 2010 (and I finally managed to install Visual Studio tools for apps, so I have access to the code).
I'm not using SharePoint since I don't have an online server, so I ask the users to save the file in a specific location (we have a shared repertory). Sorry if I'm saying things that are obvious or if I'm missing something, like I said, I'm a newbie!!
I would like for the file to be automatically named after a field where they will enter a date (not the actual date but the event date which can be 'now' but could also be on another day) followed by a number of the event since there will probably be many entries on the same day. It would look like '2016-08-26-001.xsn'. Also, I want the save location to be predetermined.
I found many C# codes that I tried putting in my coding but I always have the message :
'InfoPath cannot save the form. The form definiton file (.xsf) specifies that the saving functionality must be defined in the code, but the code does not define any event manager for OnSaveRequest.'
My InfoPath is in French... I translated the error message because I couldn't find an english version of the error message online, I hope you will understand!
These are the codes I tried:
1st code -
[InfoPathEventHandler(MatchPath="/my:myFields/my:Field1", EventType=InfoPathEventType.OnAfterChange)]
public void Field1_OnAfterChange(DataDOMEvent e) {
if(e.Operation == "Insert") {
string saveFile = thisXDocument.DOM.selectSingleNode("my:myFields/my:Field1").text;
thisXDocument.UI.SetSaveAsDialogFileName(saveFile + ".xml");
}}
2nd code -
{
string RequisitionNumber = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Header/my:RequsitionNumber", NamespaceManager).InnerXml;if (this.New || e.IsSaveAs == false)
{
if (e.IsSaveAs)
{
this.SetSaveAsDialogLocation(@"\\ccplm\sw6\req\");
this.SetSaveAsDialogFilename(RequisitionNumber);
}
e.CancelableArgs.Cancel = false;
e.PerformSaveOperation();
}
else
{
e.CancelableArgs.Message = "This functionality has been disabled.";e.CancelableArgs.MessageDetails = "Only new forms can use the 'Save As' functionality.";
}
I tried each in these two ways:
1st: going in the form options > save with custom code > modify > then Visual Studio opens and I put the code where it's written ''Type here the code to run before a 'save' or 'save as' operation''.
2nd: going in the code directly and putting the code between the { } that are after 'public void InternalStartup ()'.
I'm sorry I really tried looking for posts about this and I found many of them but the thing is that I don't know where exactly to put the code and maybe there's something I didn't do before that I don't know...
I did activate the C# coding!
I hope I have said everything you need to help me...
Thank you in advance!! :)