infopath 用webservice 获取sharepoint 当前登录名
- C# code
using Microsoft.SharePoint;[WebMethod] public DataSet getNextLeader() { SPSite spSite = new SPSite("http://hp-hu"); SPWeb web = spSite.RootWeb; string name = web.CurrentUser.Name; string sql = " SELECT e2.Name,e2.DoName FROM employee as e1,employee as e2 "; sql += " WHERE e1.Name = '{0}' AND e1.Dept = e2.Dept AND e2.duty > e1.duty "; sql = string.Format(sql,name); return db.ExecuteDataSet(CommandType.Text, sql); }infopathpublic void FormEvents_Loading(object sender, LoadingEventArgs e) { WebSerQJShenpi.QJShenpi qjsp = new sp1.WebSerQJShenpi.QJShenpi(); DataSet ds = qjsp.getNextLeader();}
单独调试的时候没有问题,但是把infopath作为审批表放到工作流里面,就不对了
然后加入进程调试,监视spSite ,出现
“由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值”
这怎么办?
[解决办法]
可能是权限问题,也可能是因为你的SPSite对象没有被释放。换成下面的代码试试:
- C# code
using Microsoft.SharePoint;[WebMethod]public DataSet getNextLeader(){ SPSecurity.RunWithElevatedPrivileges(delegate() { DataSet dsRet = null; using (SPSite site = new SPSite("http://hp-hu")) { using (SPWeb web = spSite.RootWeb) { string name = web.CurrentUser.Name; string sql = " SELECT e2.Name,e2.DoName FROM employee as e1,employee as e2 "; sql += " WHERE e1.Name = '{0}' AND e1.Dept = e2.Dept AND e2.duty > e1.duty "; sql = string.Format(sql,name); dsRet = db.ExecuteDataSet(CommandType.Text, sql); } } }); return dsRet;}
[解决办法]
你是想在infopath里获取是谁创建的表单么?
infopath里有自带的函数哦。
[解决办法]
不知我理解的对不对:
你用InfoPath来作的Task Form在workflow中使用, 你在打开Browser-Enabled InfoPath Task Form时想获取当前操作者的上一级的审批人,然后绑定到你的InfoPath 下拉列表是吗?
InfoPath Form设计的时候可以用userName() Function获取当前用户的LoginName, 绑定到任何一个字段上,你都可以在Form_Load事件中获取到。然后将你的loginname做为参数传入web service, 不能得到你想要的结果吗?