How to create an infopath form using a template and a data connection? - InfoPath Dev
in

InfoPath Dev

How to create an infopath form using a template and a data connection?

Last post 07-16-2008 02:14 PM by pweissbrod. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-16-2008 05:50 AM

    How to create an infopath form using a template and a data connection?

    Hi and thanks in advance for the help!

    I went through the trouble of designing a dynamic and clean form, but now I am a little hung up on how to deploy it to my users.

    I have a table from an ODBC source which is a list of employees.

    I want to make a web page that show the list of employees, when the user clicks on an employee, the server will send the user an infopath form with some of the employee-specific data pre-populated.

    Can someone point me in the right direction?

  • 07-16-2008 07:03 AM In reply to

    Re: How to create an infopath form using a template and a data connection?

  • 07-16-2008 09:11 AM In reply to

    Re: How to create an infopath form using a template and a data connection?

    chandrakanth --

    This is good information, but I think that what I need is a way to pre-populate some fields in an infopath form using values from a database and then send it to the user.

     

  • 07-16-2008 02:14 PM In reply to

    Re: How to create an infopath form using a template and a data connection?

    I found a solution that works for my needs. This is in C# 3.5:

    I created a gridview that lists all of the employees.

    In the gridview is a button, that fires the rowcommand:

    protected void grdEmployees_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Sort" || e.CommandName == "Page") //if you are sorting or paging, then ignore the call in this method.
                return;
           //retrieve some of the data from the selected row

            GridViewRow gridViewRow = grdEmployees.Rows[(Convert.ToInt32(e.CommandArgument))];
            string firstName = gridViewRow.Cells[1].Text;
            string lastName = gridViewRow.Cells[2].Text;
            string jobTitle = gridViewRow.Cells[3].Text;

            //open up the infopath form
            var xmlDocument = new XmlDocument {PreserveWhitespace = true}; //this is important, you need to preserve the white space of the original infopath form or else the xmldocument will add whitespace and corrupt the file
            xmlDocument.Load(@"C:\InfoPathForm.xml");
            var xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
            xmlNamespaceManager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-24T18:21:03"); //add the prefix for the "my:" namespace

            //set values
            xmlDocument.SelectSingleNode("/my:myFields/my:SubjectName", xmlNamespaceManager).InnerText = firstName + " " + lastName; //pre-populate some values from the grid into the form

            string fileName = firstName + " " + lastName;
            fileName = fileName.Replace(" ", "_") + ".xml";
            //set the response
            var stringBuilder = new StringBuilder();
            var xmlDeclaration = (XmlDeclaration) xmlDocument.FirstChild;
            xmlDeclaration.Encoding = "UTF-8";  //this is important, make sure that the encoding is UTF8
            xmlDocument.Save(new StringWriter(stringBuilder));
            Response.ClearHeaders();
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename="+fileName); //this line will force the user to save the file (instead of saving it on the browser)
            Response.ContentType = "application/xml";
            Response.ContentEncoding = Encoding.UTF8;

            //prep anything that infopath will have problems parsing
            string xmlFile = stringBuilder.ToString();
            xmlFile = xmlFile.Replace("encoding=\"utf-16\"?>", "encoding=\"utf-8\"?>");//this line is important, if you dont specify UTF8 encoding infopath will not open the document
           
            //deliver the file
            Response.Write(xmlFile);
            Response.End();
        }

     

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