Use code to access the infopath Form Content

Source: Internet
Author: User
Form is a very important feature of moss. Especially with the support of form services, infopath is often used in form solutions.CodeIt is required to access the content of the infopath form stored in the SharePoint form library.
The following three methods can be used to access the Form Content by code:
1. Improve form template attributes
2. Pass Xmldocument Object operations on form files
3. Deserialization form data architecture

Next, let's talk about the simple implementation steps of these three methods.

Method 1: Improve form template attributesForm operation:
After the form template is designed and the Publishing Wizard is executed, the form fields that you want to access through code are published, and users can edit the fields.

Access code:
First, obtain the current list item, splistitem item = infopath item, as shown in
Splistitem item = workflowproperties.
Item;Item ["workflowstatus"] = value; 
Item. Update ();

This method is simple, but it is not secure because users are allowed to edit. This method is not recommended for sensitive data.

Method 2: PassXmldocumentObject operations on form files

InfopathData is stored in XML format, so we can access form data through the XML interface.

Spfile myfile = item. file;
Stream stream = new memorystream (myfile. openbinary ());
Xmltextreader reader = new xmltextreader (Stream );
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (Reader );

Next we can analyze the XML.

Method 3:Deserialization form data architecture

InfopathForm template file. xsn is a compressed package. After the file is decompressed, it contains a description of the form data architecture. XSD file, and then. net framework's xsd.exe command line tool, through this. get a proxy class from the XSD file, and then use this class in the project.

For example, in the initialization form init. xsn of a workflow

/Deserialize workflowproperties. initiationdata to get the instance of the initial form
Xmlserializer xs = new xmlserializer (typeof (init ));

Xmltextreader XTR = new xmltextreader (new system. Io. stringreader (workflowproperties. initiationdata ));

Init init = (init) XS. deserialize (XTR );

// infopath the form content is deserialized into an object init, then you can directly access the attributes of this object.
string S = init. comments ;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.