using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Security.Principal;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
namespace Form1
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
// NOTE: The following procedure is required by Microsoft InfoPath.
// It can be modified using Microsoft InfoPath.
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string LoginName = string.Empty;
string SiteUrl = SPContext.Current.Site.Url;
string UserID = SPContext.Current.Web.CurrentUser.ID.ToString();
string EName = string.Empty;
string ID = string.Empty;
string Mobile = string.Empty;
using (SPSite Site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb Web = Site.OpenWeb())
{
SPList List = Web.Lists["User Information List"];
SPQuery Query = new SPQuery();
Query.Query = "<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + Convert.ToInt16(UserID) + "</Value></Eq></Where>";
SPListItemCollection ItemCollection;
ItemCollection = List.GetItems(Query);
if (ItemCollection.Count > 0)
{
foreach (SPListItem ListItem in ItemCollection)
{
EName = Convert.ToString(ListItem["Name"]);
ID = Convert.ToString(ListItem["ID"]);
Mobile = Convert.ToString(ListItem["MobilePhone"]);
}
}
UserProfileManager profileManager = new UserProfileManager(ServerContext.Current);
SPUser spUser = Site.RootWeb.Users.GetByID(Convert.ToInt16(UserID));
UserProfile profile = profileManager.GetUserProfile(spUser.LoginName);
XPathNavigator nav = MainDataSource.CreateNavigator();
XPathNavigator txtEName = nav.SelectSingleNode("/my:myFields/my:txtEName", NamespaceManager);
XPathNavigator txtEmpID = nav.SelectSingleNode("/my:myFields/my:txtEmpID", NamespaceManager);
XPathNavigator txtMobile = nav.SelectSingleNode("/my:myFields/my:txtMobile", NamespaceManager);
txtEName.SetValue(EName);
txtEmpID.SetValue(profile["EmployeeID"].Value.ToString());
txtMobile.SetValue(Mobile);
}
}
});
}
catch (Exception ex)
{
}
}
}
}