Custom Save Code in Form - InfoPath Dev
in

InfoPath Dev

Custom Save Code in Form

Last post 04-09-2010 09:14 AM by Mlhauburn. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-07-2010 09:09 AM

    Custom Save Code in Form

    I have created an InfoPath form in Office2007.  I have embedded code that when the user does 'Save as" the file name and path default in. This is all working fine when the user first opens the form. Where the issue starts is after the form has been emailed.

     There is logic in the form to automatically email the form to the appropriate person for approval.  When that person gets the form they can open the attachment which is the InfoPath form that was filled out.  When this person tries the 'Save As' command it always tries to save the document to their local 'My Documents' folder rather than the path specified in my C# code (also doesn't use the document name also in the code).

     I would appreciate any advice on how to get the path and file name to default when 'Save As' is used after the Infopath form has been emailed.

     Thanks in Advance for your assistnce.

    Mlhauburn
    "There's no crying in baseball!"
  • 04-07-2010 10:48 PM In reply to

    Re: Custom Save Code in Form

    can you attach the Save as code, so that we can look into it and tell you what might be going wrong

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 04-08-2010 08:12 AM In reply to

    Re: Custom Save Code in Form

     

    I guess that would be helpful wouldn't it!  :-)

     I am coding in C#.  Please be gentle I am a beginner to C#.  Thanks for the help.

    using Microsoft.Office.InfoPath;

    using System;

    using System.Windows.Forms;

    using System.Xml;

    using System.Xml.XPath;

    using mshtml;

    namespace CoachComm_Requisition_Form

    {

    public partial class FormCode

    {

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    EventManager.FormEvents.Save +=
    new SaveEventHandler(FormEvents_Save);

    ((ButtonEvent)EventManager.ControlEvents["CTRL131_5"]).Clicked += new ClickedEventHandler(CTRL131_5_Clicked);

    ((ButtonEvent)EventManager.ControlEvents["CTRL132_5"]).Clicked += new ClickedEventHandler(CTRL132_5_Clicked);

    }

    public void FormEvents_Save(object sender, SaveEventArgs e)

    {

    {

    {

    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.";

    }

    }

    // The Dirty property will be set to false if save is successful.

    e.PerformSaveOperation();

    // Write your code that will run after saving here.

    e.CancelableArgs.Cancel = false;

    }

    }

    public void CTRL131_5_Clicked(object sender, ClickedEventArgs e)

    {

     

     

    }

    public void CTRL132_5_Clicked(object sender, ClickedEventArgs e)

    {

    Xdocument.Save();

    // My attempt at a button to save form

    }

    }

    }

     

    Mlhauburn
    "There's no crying in baseball!"
  • 04-08-2010 11:16 PM In reply to

    Re: Custom Save Code in Form

    if (this.New || e.IsSaveAs == false)

    {

    if (e.IsSaveAs)  //just remove this condition.

    {

    this.SetSaveAsDialogLocation(@"\\ccplm\sw6\req\");

    this.SetSaveAsDialogFilename(RequisitionNumber);

    }

    e.CancelableArgs.Cancel = false;

    e.PerformSaveOperation();

    }

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 04-09-2010 08:05 AM In reply to

    Re: Custom Save Code in Form

    Thanks for the suggestion Qazi.  I followed your thought and commented out the line of code.  It didn't change the behaviour though...When the master form is opend and save-as is called the path and file name are defaulted.  When it is submitted (read emailed) and then opened from the email and save-as is used the defulat location is the local My Documents folder.

     

    Could the first appearance of the e.IsSaveAs == false be causing this?

     

    using Microsoft.Office.InfoPath;

    using System;

    using System.Windows.Forms;

    using System.Xml;

    using System.Xml.XPath;

    using mshtml;

    namespace CoachComm_Requisition_Form

    {

    public partial class FormCode

    {

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    EventManager.FormEvents.Save +=
    new SaveEventHandler(FormEvents_Save);

    ((ButtonEvent)EventManager.ControlEvents["CTRL131_5"]).Clicked += new ClickedEventHandler(CTRL131_5_Clicked);

    ((ButtonEvent)EventManager.ControlEvents["CTRL132_5"]).Clicked += new ClickedEventHandler(CTRL132_5_Clicked);

    }

    public void FormEvents_Save(object sender, SaveEventArgs e)

    {

    {

    {

    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.";

    }

    }

    // The Dirty property will be set to false if save is successful.

    e.PerformSaveOperation();

    // Write your code that will run after saving here.

    e.CancelableArgs.Cancel = false;

    }

    }

    public void CTRL131_5_Clicked(object sender, ClickedEventArgs e)

    {

     

     

    }

    public void CTRL132_5_Clicked(object sender, ClickedEventArgs e)

    {

    //Xdocument.Save();

    // My attempt at a button to save form

    }

    }

    }

     

     
    Mlhauburn
    "There's no crying in baseball!"
  • 04-09-2010 08:27 AM In reply to

    Re: Custom Save Code in Form

    why dont you debug your template and find out what is going wrong, to debug

    save a copy of your submitted form on your machine,

    open the form template in design mode

    in the form -> preview -> preview settings -> form name give specify the saved form.

    open the code of the form and put debug points in the submit code and press f5. and try submitting the form.

    Qazi Anis
    Technical Architect
    Bitwise Inc
    Filed under:
  • 04-09-2010 09:14 AM In reply to

    Re: Custom Save Code in Form

    BINGO!!!!!!

     The debug was a great suggestion.  I followed the process and saw that ithe form was no longer flagged as new so my code was skipped.  I copied the code to the else command sextion and BINGO!  Life is good. On to the next hurdle.

     

    Thanks So Very Much Qazi!!!!!!!!!!

    Mlhauburn
    "There's no crying in baseball!"
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.