in

InfoPath Dev

Using a field from the form to save as the filename.

Last post 12-04-2007 03:10 AM by PJagger. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-21-2007 12:03 AM

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Using a field from the form to save as the filename.

    Hi,

    I have a simple task.  I have worked out how to use the SAVEAS function to save the file to a specific location on the file system.  I need to include a field from the form in the file name.  I am sure this is an easy one, but I have searched hard to find help but to no avail.  Thanks for your help.

    Filed under: , ,
  • 11-21-2007 06:12 AM In reply to

    Re: Using a field from the form to save as the filename.

    Typical practice is to use a submit data connection.  The save and save as functionis, if you allow them, do not have any control over them and are for the user to create their own copy, which usually I do not allow any way.

    When you create a submit connection then you can set the location and the filenaming convention within it so the process is controlled and consistent.  Typically you would concatenate the filename using form data so that each one would save with a unique file name.

  • 11-25-2007 08:54 AM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Using a field from the form to save as the filename.

    Thanks for your reply,

    I am familiar with the concat function in the rules option, but would you mind showing me typical script that would use the concat function within the code which includes a field within the form.  I am not wholly up with the "syntax" of addressing fields etc within the code editor.

     Regards - Phil

  • 11-25-2007 06:52 PM In reply to

    • djay
    • Top 150 Contributor
    • Joined on 06-06-2006
    • Posts 34

    Re: Using a field from the form to save as the filename.

    There is a function to set the default save file name without using submit and locking down saves:

    thisXDocument.UI.SetSaveAsDialogFileName(string bstrFileName)

     To use this in real life it would look something like this (c#):

    [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");

    }}

     This code will autoupdate the save file name when Field1 changes.  And if you want Field1 to be a concatination of other fields you can set it's default value to something like:

    concat(Field2,"-",Field3)

  • 11-26-2007 08:26 AM In reply to

    Re: Using a field from the form to save as the filename.

    You can use the buttons in the formula window to contruct your formula, to insert formulas or fields.

    typically you would concat(namefield, "-", datefield) etc or whatever worked for you.

  • 12-04-2007 03:10 AM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Using a field from the form to save as the filename.

    Thank you

Page 1 of 1 (6 items)
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.