Getting current logged in user in VS workflow
-
2012년 6월 15일 금요일 오후 1:18
Hi
I'm having issues getting the current logged in user. this is the code I've used in my workflow (VS):
the 'SPControl.GetContextWeb(currentContext)' is undelined in redError 1 The best overloaded method match for 'Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(System.Web.HttpContext)' has some invalid arguments
SPContext currentContext = SPContext.Current; string uName = string.Empty; if (currentContext != null && currentContext.Web.CurrentUser != null) { SPWeb web = SPControl.GetContextWeb(currentContext); uName = web.CurrentUser.LoginName; } else { uName = System.Web.HttpContext.Current.User.Identity.Name; }
모든 응답
-
2012년 6월 15일 금요일 오후 1:44중재자
Hi
SPWeb web = SPControl.GetContextWeb(this.Context); string uName = web.CurrentUser.LoginName;
I may be wrong here , but I don't think you can have a context without a logged in user, that's why I omitted the if test.Kind Regards Bjoern
Blog -
2012년 6월 15일 금요일 오후 1:49
Hi
I've tried your code and this time the word Context is underlined.
Error 1 does not contain a definition for 'Context' and no extension method 'Context' accepting a first argument of type
could be found (are you missing a using directive or an assembly reference?)
SPContext currentContext = SPContext.Current; string uName = string.Empty; SPWeb web = SPControl.GetContextWeb(this.Context); uName = web.CurrentUser.LoginName; -
2012년 6월 15일 금요일 오후 2:03중재자
That didn't look correct, try:
SPWeb web = SPControl.GetContextWeb(HttpContext.Current);
+ you may have to add a
using System.Web;
Kind Regards Bjoern
Blog
- 편집됨 Bjoern H RappMicrosoft Community Contributor, Moderator 2012년 6월 15일 금요일 오후 2:04
-
2012년 6월 15일 금요일 오후 2:20
hi
Now HttpContext is underlined. I've added using System.Web
Error 1 The name 'HttpContext' does not exist in the current context
Any ideas ?
-
2012년 6월 15일 금요일 오후 2:52
You said in a workflow? There is no httpcontext in a workflow. After all, the workflow could be executing long after everyone has logged off. There is an originatoruser property of workflowproperties:
http://www.sharepointkings.com/2008/08/how-to-get-currently-logged-in-user-in.html
Mike G.
-
2012년 6월 16일 토요일 오전 9:32
Hi
I just tried the link above and it doesnt work either, I get the person who created the list item and not the person who completed the task.
I've come to realise that there could be a number of people logged in at any one time. I want the person who completed the task in the workflow.
Thanks
-
2012년 6월 18일 월요일 오전 7:43
Hi orange juice jones,
You can get the person who complete the task in workflow by the code below:
private void completeTask1_MethodInvoking(object sender, EventArgs e) { SPListItem item = workflowProperties.TaskList.GetItemById(TaskProperties1.TaskItemId); SPUser user =(SPUser) item["Modified By"]; }
Thanks,
SimonSimon Huang
TechNet Community Support
- 답변으로 표시됨 Shimin Huang 2012년 6월 21일 목요일 오전 7:18

