How to retrieve Save As file path? - InfoPath Dev
in

InfoPath Dev

How to retrieve Save As file path?

Last post 05-08-2008 07:23 AM by sturge. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-07-2008 06:26 AM

    • sturge
    • Not Ranked
    • Joined on 05-06-2008
    • Posts 4

    How to retrieve Save As file path?

    When the user saves an InfoPath form, I need to trigger some logic that will create another file based on the file name typed by the user in the Save As dialog.  Although MSDN suggests that I should be able to retrieve the file name from the SaveEventArgs.Filename property, this is not the case.  If the operation is Save As, the Filename property is empty even after PerformSaveOperation is called.

    Here is some sample code:

     public void FormEvents_Save(object sender, SaveEventArgs e)
     {
         // Write your code that will run before a Save or Save As operation here.

         // The Dirty property will be set to false if save is successful.
              
         e.PerformSaveOperation();
         String s = e.Filename;

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

         e.CancelableArgs.Cancel = false;
     }

    In this example, the string s is empty if the operation is Save As.  It is populated only when the operation is Save.  MSDN says the following about the SaveEventArgs.Filename property:

    If the IsSaveAs property of the SaveEventArgs object is true, and a save operation has not yet occurred, the FileName property returns an empty string. If the IsSaveAs property is true and a save operation has already occurred, the value returned by the FileName property is the file name under which the form was saved.

    So, Filename should be getting populated with the name the user typed, but it isn't.  What gives?  Has anyone else encountered this problem and found a good workaround?

    Filed under: ,
  • 05-07-2008 12:12 PM In reply to

    Re: How to retrieve Save As file path?

    Hi There and Welcome to the forum.

    One Question i have is why are you allowing save as?

    Best practice would be to setup a dataconnection to submit the document. Then you can both specify a standard naming convention, such as lastname, first - date.xml or whatever you want to build from your form data. Also then you have the path saved in your form to be used for other things such as you describe.

    I have not tried anything with the save as coding since I avoid that when ever possible since it is difficult to control and manage.

  • 05-08-2008 07:23 AM In reply to

    • sturge
    • Not Ranked
    • Joined on 05-06-2008
    • Posts 4

    Re: How to retrieve Save As file path?

    Hi,

    Thanks for your reply.  Basically, we are trying to get a proof of concept going for a customer company where users will be filling out InfoPath forms.  We don't yet have a full set of requirements, but we do know that we need to hook into the form at the point where the xml form data is generated and create a parallel, proprietary file based on that data.  So, if the user generates test.xml, our initial plan was to generate test.abc, with the same file name and in the same file system location.  The first thing I tried for this was hooking into the Save functionality.  I thought that it would be a lighter-weight solution than creating a data connection. 

    This may turn out not to be possible, or the hook might need to go elsewhere (i.e., Submit) once we get the full requirements and have more information about the intended workflow.  In any case, it seems to me that the fact that SaveEventArgs.Filename does not get populated for Save As must be a bug in the Microsoft code.

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