Hesham

See also: Other Geeks@INDC

Creating Custom web page in MOSS 2007 via XmlFormView ASP.Net Control

Introduction
Creating a custom web page in MOSS 2007 to render browser –enabled, interactive info path forms via XmlFormView ASP.Net Control.

Steps
A) Creating the new web page & Adding the XmlFormView control:
  • Click , Start > Administrative Tools > Internet Information Services (IIS) Manager, Then expand the Server Name (local computer) in order to have the list of IIS services that are available on the server. Then expand the Web Sites to show the list of web sites that are managed by IIS then right click sharepoint – 80 and then click properties then on the ASP.Net tab of the sharepoint-80 properties dialog box, highlight and copy the text in the File location box without copying the web.config that appears at the end of the File Location string as shown in these figures:

 

Click to enlarge
 

 

Click to enlarge 

Then start Visual Studio.Net 2005 , File > Open > Web Site > File System , then in the folder box paste the file location path that you copied then click open , as shown in the figure:

Click to enlarge 

Then right click on the path of the web site in solution explorer and select New folder and name it “XmlFormView” then right click on the new folder and select Add new item > Web form and name it “MyCustomPage” and select place code in separate file then click add as shown in the figure: 

Click to enlarge 

Then add the XmlFormView control to the “MyCustomPage.aspx” web page , then in the Document Properties for “MyCustomPage.aspx” page click True for the EnableSessionState property as shown in the figure:

Click to enlarge 

Then at the source view , remove the default Doctype declaration tag which begins with <! DOCTYPE html PUBLIC , and modify the Body tag to contain the folowwing style atrributes : 

style="margin: 0px;overflow:auto;padding:20px"

 

 then modify the Form tag to contain the following enctype attribute :

 

enctype="multipart/form-data"
Click to enlarge

 

Then in the Design view, add XmlFormView control from the Toolbox then from its properties in the Data Binding section Paste the URL to browser – enabled form template in XsnLocation Property of the control But first let’s design a form template To be used: Open MS Office InfoPath 2007 > Design a Form Template > Form Template > Blank > Enable browser – compatible features only, as Shown in the figure:

Click to enlarge 

Then in the task pane > Controls > Add Date picker > Date Picker Properties > click the function button to the right of the value Box > then in the Insert formula box > Insert Function > Click Today function > Ok, as shown in the figure:

Click to enlarge 

Then add an optional section to the form >(Section properties) then On Data tab > Click Include the section in the form by default > in Display tab > click conditional formatting > in Conditional format Box > Add > confirm that the first drop down box contains field1 Which bound to the date picker control otherwise change it to field1 > In third box under If this condition is true > click drop down List > select use a formula > Insert formula box > click Insert Function > Click today function > Ok > in Conditional format box > Shading drop down list and select a color > Ok, as shown in these Figures:

Click to enlarge 

 

Click to enlarge 

Then repeat the previous steps again but select a different color To use when the field1 is later than today date and for when field1 Is earlier than today date, as shown in the figure:

Click to enlarge 

Then, File > Publish > to a sharepoint server with or without InfoPath forms services > Next, as shown in these figures:

Click to enlarge 

Click to enlarge 

Then, select enable this form to be filled out by using a browser > Select Document library > Next, as shown in the figure:

Click to enlarge 

Then, click creates a new document library > Next, as shown in the figure:

Click to enlarge 

Then, type a name for the new document library > Next, as shown in the figure:

Click to enlarge

Then click, Next > Publish, as shown in the figure:

Click to enlarge 

Then, click Open this form in the browser in the publishing wizard box, as shown in the figure:

Click to enlarge 

Then in the address bar in IE copy the XsnLocation portion of the URL starting after the equal sign (=) with “http” and ending with “.xsn” then close the browser , as shown in the figure:

Click to enlarge 

Then close the wizard as shown in the figure:

Click to enlarge 

Then, go back to the XmlFormView control > XsnLocation property > Paste the URL you got, as shown in the figure:

Click to enlarge 

Then, on the website menu > Start Options > Start actions section: click start URL to your custom page such as: http://ServerName/XmlFormView/MyCustomPage.aspx, as shown in these figures:

Click to enlarge 

Click to enlarge 

Then click Ok, then on File menu > click save all and give a solution a name and location. Then click, Start > All programs > Microsoft visual studio 2005 > visual studio Tools > open visual studio 2005 command prompt window, as shown in the figure:

Click to enlarge 

Then type iisreset> Enter, then close the prompt window, as shown in the figure:

Click to enlarge

Then debug the web page: Save the custom web page > press F5 to start debugging , if you receive a message that states the web.config file not being configured for debugging , click ok which automatically adds the debug flag to the web.config file , as shown in the figure:

Click to enlarge 

B) Passing a value from the template form to the web page :

    • Add these namespaces:

      Using System.Xml;

      Using System.Xml.XPath;

      Then add a Textbox control: as shown in the figure:

Click to enlarge 

Then in the Button click event, write this code:

protected void Button1_Click(object sender, EventArgs e)

    {

        XmlFormView1.DataBind();

        XPathNavigator xNavMain =

           XmlFormView1.XmlForm.MainDataSource.CreateNavigator();

        XmlNamespaceManager xNameSpace =

           new XmlNamespaceManager(new NameTable());

        xNameSpace.AddNamespace("my", XmlFormView1.XmlForm.NamespaceManager.

           LookupNamespace("my").ToString());

        TextBox1.Text = xNavMain.SelectSingleNode(

           "/my:myFields/my:field2", xNameSpace).ToString();

    }

as shown in the figure:

Click to enlarge 

C) Passing a value from the web page to the template form:

  • Add another Textbox control to both the web page and the info path browser – enabled form template rendered in the XmlFormView control , Then switch to the source view of your web page and locate the tag for the XmlFormView1 control as:
<cc1:XmlFormView ID="XmlFormView1" runat="server" Height="250px"
    Width="100%"
XsnLocation="http://ServerName/DocumentLibrary/Forms/template.xsn">

 

  Then declare the name of the Initialize event handler in the XmlFormView1 control tag, as:
<cc1:XmlFormView ID="XmlFormView1" runat="server" Height="250px"
    Width="100%"
XsnLocation="http://ServerName/DocumentLibrary/Forms/template.xsn"
OnInitialize="XmlFormView1_Initialize" />
 

Then in the Initialize event handler, write:

protected 
    void XmlFormView1_Initialize(object sender, 
   InitializeEventArgs
    e)
{
    XPathNavigator
    xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
    XmlNamespaceManager
    xNameSpace = new XmlNamespaceManager(new
    NameTable());
    xNameSpace.AddNamespace("my", "http://schemas.microsoft.com 
/office/infopath/2003/myXSD/2006-04-20T16:26:21"
);
    XPathNavigator
    fTextBox1 = xNavMain.SelectSingleNode(
       
"my:myFields/my:field2", xNameSpace);
       
fTextBox1.SetValue(TextBox1.Text);
}

As shown in the figure:

Click to enlarge 

D) Submitting Data from the form :

  • Create a SubmitToHostAdapter data connection in the form template that is hosted in a custom web page : Open InfoPath form template in design mode > Tools menu >Data Connections > Add > Create a new connection > Submit Data > Next > Select To the hosting environment, such as an ASP.Net page or a hosting application > Next, as shown in the figure:

Click to enlarge 

Then type a name for the new data connection > Finish. Then enable the form to submit its XML data to the hosting environment: Tools menu > Submit Options > Allow Users to submit this form > then in the first drop down list > select Hosting environment > and in the second list > select the name you gave to the data connection, as shown in the figure:

Click to enlarge 

Then click Ok, and Republish the form template to the same document library on the sharepoint server or create a new document library, Then go back to the VS solution, and write this code in the Submit ToHost event handler of the XmlFormView1 control:

protected 
    void XmlFormView1_SubmitToHost(object sender, 
   SubmitToHostEventArgs
    e)
{
   // Create an XPathNavigator positioned at the root of 
   // the form's main data source.
   XPathNavigator
    xNavMain = 
      
    XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
   // Create an XmlNamespaceManager and add the 
        "my" namespace
   // alias from the form's main data source.
   XmlNamespaceManager
    xNameSpace = 
      
    new XmlNamespaceManager(new
    NameTable());
   xNameSpace.AddNamespace("my", "http://schemas.microsoft.com/ 
office/infopath/2003/myXSD/2006-04-20T16:26:21"
);
   // Create an XPathNavigator positioned on the form's field2.
   XPathNavigator
    fTextBox1 = xNavMain.SelectSingleNode(
      
    "my:myFields/my:field2", xNameSpace);
   // Set TextBox1 on the page to the value in the form's field2.
   TextBox1.Text
    = xNavMain.SelectSingleNode(
      
    "/my:myFields/my:field2", xNameSpace).ToString();
}

As shown in the figure:

Click to enlarge 

 

 

 

 

 Copyright © 2006 Innovation-Hut. All Rights Reserved. |  Terms of Use  |    Privacy Statement   |   FAQ    <Hesham Saad Aly>
var sc_project=2000388; var sc_invisible=1; var sc_partition=18; var sc_security="1901aa3d";
Share this post: | | | |

Comments

seizedcarautos said:

Hello to all ! Great site. I am new here greetings to all from Poland.

# April 10, 2009 1:38 PM

cheapfastcars said:

Hello I am new here.

<a href=carauctions444.unl.pl/cheap-fast-cars.html>cheap">carauctions444.unl.pl/cheap-fast-cars.html>cheap fast cars</a>

<a href="carauctions444.unl.pl/cheap-fast-cars.html">Cheap">carauctions444.unl.pl/cheap-fast-cars.html">Cheap Cars</a>

Cheap Fast Cars - carauctions444.unl.pl/cheap-fast-cars.html

# April 28, 2009 1:22 PM

repocarauctions said:

# May 2, 2009 6:04 PM

Pharmc701 said:

Very nice site!

# May 23, 2009 11:46 PM