Friday 7 June 2013

Displaying the user details in InfoPath based on user with code:

Displaying the user details in InfoPath based on user with code:
1.design form
2) Form options àsecurity and trustàFull trust
3) Select language to c#.right click on button click on edit form code

Code

SPSite site = new SPSite("http://syncgdc1412:3333/sites/Testingsite");
            SPWeb web = site.OpenWeb();
            SPList list = web.Lists["User Information List"];
            XPathNavigator xpnav = this.CreateNavigator().SelectSingleNode("/my:myFields", this.NamespaceManager);
            XPathNavigator xpnav1 = xpnav.SelectSingleNode("/my:myFields/my:username", this.NamespaceManager);
            string s = xpnav1.ToString();
            SPListItemCollection itemcol;
            SPQuery qry = new SPQuery();
            qry.Query = "<Where><Or><Eq><FieldRef Name='Title' /><Value Type='Text'>" + s.ToString() + "</Value></Eq><Eq><FieldRef Name='UserName' /><Value Type='Text'>" + s.ToString() + "</Value></Eq></Or></Where>";
                //"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + s.ToString() + "</Value></Eq></Where>";
            itemcol = list.GetItems(qry);
            foreach (SPListItem item in itemcol)
            {
                xpnav.SelectSingleNode("/my:myFields/my:field2", this.NamespaceManager).SetValue(item["EMail"].ToString());
                //xpnav.SelectSingleNode("/my:myFields/my:Phone", this.NamespaceManager).SetValue(item["MobilePhone"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:SipAddress", this.NamespaceManager).SetValue(item["SipAddress"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:Department", this.NamespaceManager).SetValue(item["Department"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:JobTitle", this.NamespaceManager).SetValue(item["JobTitle"].ToString());


4)view certificateàany errorsàcopy or create certificateàsave the certificate in desktopàgoto runàmmcàright click on Console1àAll tasksàImport(IMPORT THE CERTIFICATE)àAFTER THAT GO AND CHECK IF THERE IS ANY ERRORS IN THE FORM.

5)Publish to form library.            }

No comments:

Post a Comment