如何获得当前登录INFOPATH用户的用户组
在表单的启动事件中插入如下的代码,就可以获得当前用户的所有用户组:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;
namespace 得到用户的组
{
public partial class FormCode
{
// 启用浏览器功能的表单不支持成员变量。
// 请使用代码从 FormState 词典
// 写入和读取这些值,如下所示:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
{
public partial class FormCode
{
// 启用浏览器功能的表单不支持成员变量。
// 请使用代码从 FormState 词典
// 写入和读取这些值,如下所示:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
// 注意: 以下是 Microsoft Office InfoPath 所需的过程。
// 可以使用 Microsoft Office InfoPath 对其进行修改。
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
// 可以使用 Microsoft Office InfoPath 对其进行修改。
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
// 在此处编写代码。
{
// 在此处编写代码。
try
{
{
string userString = System.Environment.UserDomainName + "\\" + System.Environment.UserName;
SPSecurity.RunWithElevatedPrivileges(delegate() //用此方法模拟管理员账户运行此事件处理程序
{
{
SPSite site = new SPSite("http://www.dosboy.net/");
SPWeb myweb = site.RootWeb;
myweb.AllowUnsafeUpdates = true;
SPWeb myweb = site.RootWeb;
myweb.AllowUnsafeUpdates = true;
SPUser user = myweb.EnsureUser(userString);
XPathNavigator myN = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field2", NamespaceManager);
myN.SetValue(user.Name);
SPGroupCollection groups = user.Groups;
string ss = "";
foreach (SPGroup group in groups)
{
ss += group.ToString() + ";";
}
myN = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field2", NamespaceManager);
myN.SetValue(ss);
});
}
catch (Exception ex)
{
XPathNavigator myN2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field2", NamespaceManager);
myN2.SetValue(ex.Message );
}
{
XPathNavigator myN2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field2", NamespaceManager);
myN2.SetValue(ex.Message );
}
}
}
}

浙公网安备 33010602011771号