Saving without user interface - InfoPath Dev
in

InfoPath Dev

Saving without user interface

Last post 10-24-2005 05:59 PM by franck. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 10-24-2005 07:57 AM

    Saving without user interface

    Hi All, I've seen a couple of questions like this one, but nothing that is the same as my issue.

    I am using Infopath 2003 with SP1, C# Managed Code.

    I have a button on my form, that when the user clicks it the form needs to save to a sharepoint library. The file name will be preset based on a field in the form.

    Here is my code for the command button,

    [InfoPathEventHandler(MatchPath="cmdSave", EventType=InfoPathEventType.OnClick)]
    public void cmdSave_OnClick(DocActionEvent e)
    {
    // Write your code here.
    UpdateStatus(); //runs some processing for hidden fields before saving

    IXMLDOMNode objNumberNode;
    objNumberNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:Client/my:Customer/my:Number2");
    if (objNumberNode.text != "")
    {
    thisApplication.ActiveWindow.XDocument.SaveAs(objNumberNode.text + ".xml");
    }
    }

    Now, if I use the save icon in the tool bar and save the document first, then come back here it works, because the file name has been set. If I just click the command button to save a new form then it does not work. I have verified that objNumberNode.txt has a string in it and tried it with a set string to be sure (ie "ABC.xml") with no luck. Here is the exact error I am getting.

    InfoPath cannot save the form with the following name: XYZ.xml
    The following URL, path, or file name is invalid: XYZ.xml
    The file path referred to by an object model call must be absolute.

    I have also gotten an error as I experimented with code that says file does not have a name.

    Any help with this would be greatly appericated.

    Thanks

    Lee
  • 10-24-2005 08:14 AM In reply to

    Re: Saving without user interface

    Hi Lee,

    You have to take over the Save behavior of the Form through the OnSaveRequest.
    Go to Tools \ Form Options \ Open and Save Tab \
    Check: Save using custom code \ Edit
    Call your code from there.

    Hope that it helps.

    Regards,

    Franck Dauché
  • 10-24-2005 08:32 AM In reply to

    Re: Saving without user interface

    Hi Franck, here is the existing code from that function, I had already added functionality to that as is described on the MS site. This code works good if it is an existing form that I have re-opened or if the user clicks the save icon in the tool bar. But I need to be able to start the save process from code on a new form that has not yet been saved. It appears if I could call the SaveEvent e from my command button code I could make this work, but I cannot even call the OnSaveRequest from my command button code.

    Thanks

    [InfoPathEventHandler(EventType=InfoPathEventType.OnSaveRequest)]
    public void OnSaveRequest(SaveEvent e)
    {
    // Write the code to be run before saving here.
    UpdateStatus();

    if (thisXDocument.IsNew == true || e.IsSaveAs == false)
    {
    IXMLDOMNode objSerialNumberNode;
    objNumberNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:Client/my:Customer/my:Number2");
    if (objlNumberNode.text != "")
    {
    e.IsCancelled = e.PerformSaveOperation();
    // Write the code to be run after saving here.
    e.ReturnStatus = true;
    }
    else
    thisXDocument.UI.Alert("Please enter the name number for this form");
    }
    else
    {
    thisXDocument.UI.Alert("The 'Save As' functionality is disabled for forms that are not new.");
    }
    }
  • 10-24-2005 09:40 AM In reply to

    Re: Saving without user interface

    Then, why don't you think of it the other way around. If possible in your workflow:
    When a new form is requested by your user, create a WhateverNameYouWant.xml document based on your template (on your user's machine), and open it up.

    Anyway, to come back to your issue, SaveAs needs an absolute path, such as: C:\\XYX.xml

    Regards,

    Franck Dauché
  • 10-24-2005 09:57 AM In reply to

    Re: Saving without user interface

    Hi Franck, seems I would be over complicating a simple issue (or what should be I think), I have tried to set a full path in the .SaveAs event back to the Sharepoint site but still get the error. The documentation says that the .Save event does not need a file name, I guessed then that this would be the same as clicking the save icon on a new form. But it would appear that infopath sets something first when I click the save icon, because that works, but my save button that calls thisXDocument.Save() does not, yet both those do call the OnSaveRequest event.

    Is there a way I can set the URI name of the form (which is what I think infopath is looking for when I call the thisXDocument.Save() event), or a way that I can open the save as dialog box? Or using some MS Office macrolike function call the save command from the menu?

    Thanks
  • 10-24-2005 10:31 AM In reply to

    Re: Saving without user interface

    I am confused now, do you to save locally? C:\\XYZ.xml or submit back to Sharepoint?
    To get the dialog box, you need to look into:
    thisXDocument.UI.SetSaveAsDialogFileName("YourName");
    To submit to Sharepoint by code, you will need a DAVAdapter...


    Regards,

    Franck Dauché
  • 10-24-2005 10:45 AM In reply to

    Re: Saving without user interface

    I am saving back to the sharepoint library. Not submitting.

    I cannot use the submit because if I create a submit button using a data connector, etc, etc, the submit works BUT does not execute my custom logic first and as such the form is submitted with the wrong values in some of the fields. If there is a way you can tell me that I can fire my custom logic first, then have the form submit, using a submit button then this would work.

    So now, I have it almost working using a save command (I'm not sure what the different with save/submit is when they both go to the same sharepoint library). It works great, except on the first save. In fact I like it better then the submit, because infopath remembers where I opened it from and I don't have to specify the location like do with a data connector and a submit button. Forinstance, if I click the save icon in the tool bar on the first save, the Save As dialog will open right to the sharepoint library where I opened the template from, I even have the file name correctly filled in from the required field in the form. All the user needs to do is click Save and it's done. But I cannot get that first save, save as dialog box to open via code.
  • 10-24-2005 10:47 AM In reply to

    Re: Saving without user interface

    further, I have the save as file name already set using the thisXDocument.UI.SetSaveASDialogFileName(stringhere); But that does not open the save as dialog box, it only sets the name for when it gets opened later.
  • 10-24-2005 02:18 PM In reply to

    Re: Saving without user interface

    Hey there, while I'd like to know why the thisXDocument.Save() was not working as was documented I have a work around.

    The functions that would have called the thisXDocument.Save() event I have placed a check thisXDocument.IsNew() if the is new returns true then the use gets a message box saying they must save the form first using the save icon. After that the code works fine for the saves after that.

    Where this came from is when the user digitally signs the form, I want it to save automaticly when signed so if they close without saving after that, then it will still be signed.

  • 10-24-2005 05:59 PM In reply to

    Re: Saving without user interface

    Lee, did you try to call your code from the OnContextChange event (with the check for IsNew(), but to try to call your code automatically)? Just a thought...

    Regards,

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