Add vsta hosting code to infopath and query data from Sharepoint list

Source: Internet
Author: User
In the loading event, add the following code:
If (this. New) // if it is a new form, configure the original value.
{
// Obtain the fullname value of the current user in the configuration file
Using (spsite site = new spsite ("http: // oss") // replace this value with the URL of your SharePoint site
{
// The following configuration files are obtained based on the current user login name:
Servercontext context = servercontext. getcontext (SITE );
Userprofilemanager profilemanager = new userprofilemanager (context );
USERPROFILE u = profilemanager. getuserprofile (this. application. User. loginname );
String fullname = U [propertyconstants. preferredname]. value. tostring ();
 
Windows XP athnavigator mainnavigator = This. maindatasource. createnavigator (); // retrieve the cursor of the primary data source
 
// Configure the applicant's node value as the user name, that is, the preferredname attribute in the configuration file
Mainnavigator. selectsinglenode ("/My: myfields/My: Applicant", this. namespacemanager). setvalue (fullname );
          
// Query a department from the SharePoint department list by name
Using (spweb = site. allwebs ["/demo"]) // replace this with the URL of your SharePoint site
{
Spquery query = new spquery ();
// Because the name field is modified from the title, its internal name is Title
Query. query = "<where> <EQ> <fieldref name = 'title'/> <value type = 'text'>" + fullname + "</value> </EQ> </Where> ";
Splist list = web. Lists ["department staff"];
Splistitemcollection items = List. getitems (query );
If (items. Count> 0) // configure the department value if it is found.
Mainnavigator. selectsinglenode ("/My: myfields/My: applying for a department", this. namespacemanager). setvalue (items [0] ["department"]. tostring ());
 
}
 
}
}
}

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.