Custom Save Button - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Custom Save Button

Last post 04-08-2011 11:03 AM by ashoke. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 12-03-2010 01:49 AM

    • renato
    • Not Ranked
      Male
    • Joined on 12-02-2010
    • Romano
    • Posts 16

    Custom Save Button

    Hi All,

    I'm trying to define custom buttons on my Infopath 2003 (filler) form to achieve simpler submit/save operations for users. My scenario is as follows:

    1) User may start filling a new form: in this case I want them to be able to a) Save the form locally (a kind of a draft) or b) submit the form (to a SP library)

    2) User may open and modify a form which is already on the SP library; in that case I want them to be able to c) save their changes.

    I'm able to discriminate 1) and 2) - also submitting the form works fine, saving changes works fine, but where I'm struggling is on a) making them able to save a local draft, because thisXDocument.Save() will only work if the form is already saved (either locally or on the SP library), whereas thisXDocument.saveas requires a path to the file where to save the form, while I want the save as dialog box to pop up (the first time - as for any office document). That would be what the default save button does, but I'm trying to achieve the same on a custom button to facilitate users which I'm sure would be struggling with Submit/Save...

    At the end what I'm looking for is a custom save button which behaves as the default infopath save button. Any help is very appreciated, thanks

    Renato

  • 12-03-2010 03:46 AM In reply to

    Hi Renato,

    Stupid question but why not use the out-of-box support for save? Why do you need to make this a button?

    We've developed and delivered hundreds of InfoPath forms. We've done a lot of work to customize Save for offline scenarios (for example, adding conflict resolution detection, etc.) but we've never ever tried to popup a Windows save dialog. The other issue with forcing this is that you will have to be full trust which is not a best practice. I recommend just teaching the users to use the default controls.

    Sorry for the lack of a solution.

    Patrick Halstead
    Project Manager at Qdabra
  • 12-03-2010 04:26 AM In reply to

    • renato
    • Not Ranked
      Male
    • Joined on 12-02-2010
    • Romano
    • Posts 16
    You're right Patrick, that is just a way to make it easier and clearer for users, which are potentially hundreds, maybe 1 thousand. I'm trying to have "submit" and "save" buttons close in the form and reduce the number of possible choices for users, that's the only point. Anyway a found a post on a different site which helped me a bit. I'm posting my solution for the Onclick event of the save button, in case anyone is interested: public void CTRL108_8_OnClick(DocActionEvent e) { // try a straight save (will work if document had already been saved try { thisXDocument.Save(); } catch (Exception ex1) { SaveFileDialog saveas = new SaveFileDialog(); saveas.AddExtension = true; ; saveas.DefaultExt = "xml"; saveas.Filter = "XML Documents (*.xml)|*.xml|All Files (*.*)|*.*"; // Set a default file name from entered data string projectTitle = thisXDocument.DOM.selectSingleNode("/my:myFields//blabla").text; if (projectTitle == null || projectTitle == "") { projectTitle = "New Project"; } saveas.FileName = projectTitle + " - Gate 4"; DialogResult result = saveas.ShowDialog(); if (result == DialogResult.OK) { thisXDocument.SaveAs(saveas.FileName); } } }
  • 12-03-2010 05:55 AM In reply to

    That's cool. Wonder if full trust is still required though.

    One more idea that is codeless and doesn't require full trust: add a Submit button and label it Save. You can set the name programmatically based on unique keys in the form. Assumes it is going to a server though and won't work to save locally.

    Patrick Halstead
    Project Manager at Qdabra
  • 04-05-2011 12:10 PM In reply to

    • ashoke
    • Not Ranked
      Male
    • Joined on 02-24-2011
    • Toronto, Canada
    • Posts 21

    Hi Renato, Thanks for posting your solution code. I'm in a similar situation where I need to add a button that will pop up a window for Save As. Mine is in InfoPath 2007 full trust connected to Access db. For some reasons, DocActionEvent is not supporting. It's driving me nuts. Any help would be highly appreciated? Thanks for your help in advance. Ash

  • 04-06-2011 12:06 AM In reply to

    • renato
    • Not Ranked
      Male
    • Joined on 12-02-2010
    • Romano
    • Posts 16

    Unfortunately I'm not that familiar with the IP2007 API, nor with DB-connected forms. Actually I would like to deepen that second subject as I'm starting development on a DB-connected form (though still on IP 2003 filler forms). Specifically I'm wondering if I still need to save the forms' XML, and wether/how the form XML is linked to the DB table record... Sorry if I answer with a question...

  • 04-08-2011 11:03 AM In reply to

    • ashoke
    • Not Ranked
      Male
    • Joined on 02-24-2011
    • Toronto, Canada
    • Posts 21
    Hi - I have solved the issue with minor tweak. I needed the button to pop up Save As dialogue box all the time. I thought someone might be benefitted from my codes which are done on IP 2007 connected to Access db. Thanks, Ash 

    SaveFileDialog saveas = new SaveFileDialog();

    saveas.AddExtension = true;

    saveas.DefaultExt = "xml";

    saveas.Filter = "XML Documents (*.xml)|*.xml";

    // Set a default file name from entered data

    string form_ID = this.MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:top/@ID", this.NamespaceManager).Value;if (form_ID == null || form_ID == "")

    {

    form_ID =
    "New Project";

    }

    saveas.FileName = form_ID;

    DialogResult result = saveas.ShowDialog();if (result == DialogResult.OK)

    {

    this.SaveAs(saveas.FileName);

    }

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