Reload a Infopath form on page load - InfoPath Dev
in

InfoPath Dev

Reload a Infopath form on page load

Last post 09-02-2008 03:25 AM by Shiva. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-31-2008 06:38 AM

    Reload a Infopath form on page load

    Hi, I make a web site using the XmlFormView to showing infopath form publish in SharePoint 2007.  All this part working fine.  I'm able to store the xml of the infopath form no problemo and I'm able restore the value in the field on the infopath form to.  But I want to able to restore the field value when the page was load.  The only way I fount rigth now is to put to code in a button code.  I make a webservice to connect to the database to store and give the xml of the infopath.  The problem I found is the value was put into the infopath but not showing. 

     If somebody can help me is very appreciate.

     He are my code of my asp.net page :

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Microsoft.Office.InfoPath.Server.Controls;
    using Microsoft.Office.InfoPath;
    using System.Xml;
    using System.Xml.XPath;

    public partial class MyFolder_NewExpense : System.Web.UI.Page
    {
        private int ProcessusID = -1;
        private bool FormLoaded;


        protected void Page_Load(object sender, EventArgs e)
        {
            ProcessusID = -1;
            FormLoaded = false;
            XmlFormView1.XsnLocation = "~sitecollection/allo/Forms/template.xsn";
            XmlFormView1.EditingStatus = XmlFormView.EditingState.Editing;
            if (Request.Params["processusid"] != null)
            {
                ProcessusID = System.Convert.ToInt32(Request.Params["processusid"]);
            }
        }

        protected void LoadDataInFormView(int processus_id)
        {
            XmlDocument test1 = new XmlDocument();
            String webresult;
            WebReference.Service2 WebService = new WebReference.Service2();
            WebService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            webresult = WebService.GetAProcessusData(processus_id);

            test1.LoadXml(webresult);

            XmlFormView1.DataBind();
            XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();

            XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable());

            xNameSpace.AddNamespace("my", XmlFormView1.XmlForm.NamespaceManager.LookupNamespace("my").ToString());

            XmlNode KilometreSource = test1.SelectSingleNode("/my:mesChamps/my:Kilometre", xNameSpace);
            XmlNode RepasSource = test1.SelectSingleNode("/my:mesChamps/my:Repas", xNameSpace);

            XPathNavigator Kilometre = xNavMain.SelectSingleNode("/my:mesChamps/my:Kilometre", xNameSpace);
            XPathNavigator Repas = xNavMain.SelectSingleNode("/my:mesChamps/my:Repas", xNameSpace);

            Kilometre.SetValue(KilometreSource.FirstChild.Value);
            Repas.SetValue(RepasSource.FirstChild.Value);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Server.Transfer("ProcessusList.aspx");
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            XmlFormView1.DataBind();
            XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
            WebReference.Service2 WebService = new WebReference.Service2();
            WebService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            WebService.SaveProcessus(xNavMain.OuterXml, 1); //type a 1 est pour les compte de depense et les type a 2 sont les formulaire d'envoi
            Server.Transfer("ProcessusList.aspx");
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            XmlFormView1.XsnLocation = "~sitecollection/allo/Forms/template.xsn";
            XmlFormView1.EditingStatus = XmlFormView.EditingState.Editing;
        }
        protected void XmlFormView1_Initialize(object sender, InitializeEventArgs e)
        {
            if (!FormLoaded)
            {
                FormLoaded = true;
                if (ProcessusID != -1)
                    LoadDataInFormView(ProcessusID);
            }
        }
        protected void Button1_Click1(object sender, EventArgs e)
        {
            if (ProcessusID != -1)
                LoadDataInFormView(ProcessusID);
        }
    }

  • 09-02-2008 03:25 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Reload a Infopath form on page load

    Hello Eric Welcome to the Forums,

    How do you know the value is setting to xml and it is not showing in InfoPath form? Did you debug it and it is updating with new value?

    If you get any error while debug the form then give us error description where you are getting that error?

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