Getting current logged in user in VS workflow
-
15 Haziran 2012 Cuma 13: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; }
Tüm Yanıtlar
-
15 Haziran 2012 Cuma 13:44Moderatör
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 -
15 Haziran 2012 Cuma 13: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; -
15 Haziran 2012 Cuma 14:03Moderatör
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
- Düzenleyen Bjoern H RappMicrosoft Community Contributor, Moderator 15 Haziran 2012 Cuma 14:04
-
15 Haziran 2012 Cuma 14: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 ?
-
15 Haziran 2012 Cuma 14: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.
-
16 Haziran 2012 Cumartesi 09: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
-
18 Haziran 2012 Pazartesi 07: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
- Yanıt Olarak İşaretleyen Shimin Huang 21 Haziran 2012 Perşembe 07:18