<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Get Current User on Matt Thornton</title>
    <link>http://localhost:1313/tags/get-current-user/</link>
    <description>Recent content in Get Current User on Matt Thornton</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Wed, 04 May 2011 17:34:08 +0000</lastBuildDate><atom:link href="http://localhost:1313/tags/get-current-user/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>SharePoint &#43; Visual Studio &#43; Get Current User</title>
      <link>http://localhost:1313/tech/sharepoint/sharepoint-visual-studio-get-current-user/</link>
      <pubDate>Wed, 04 May 2011 17:34:08 +0000</pubDate>
      
      <guid>http://localhost:1313/tech/sharepoint/sharepoint-visual-studio-get-current-user/</guid>
      
        <description>&lt;p&gt;A frequently asked question in the MSDN forums is “how you can get access to the user who is interacting with your workflow?”. For example, the user modifying a task. The workflow is likely running in a different context and/or session to your browser session so there&amp;rsquo;s not an obvious tie-up.&lt;/p&gt;
&lt;p&gt;However, in this scenario, you can get the login name of the person who modified the SharePoint task, via the Executor property of the OnTaskChanged event. Simply bind the Executor property to a string (e.g., “taskLastModifiedBy”) and whenever the task changes, SharePoint will copy the user ID to this property in the format of DOMAIN\LoginName. You can then get an &lt;a href=&#34;http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx&#34;&gt;SPUser object&lt;/a&gt; for that login name with, e.g.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;SPUser user = workflowProperties.Web.AllUsers[taskLastModifiedBy];&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On a related subject, and the thing that prompted this post - if you&amp;rsquo;re trying to update a &lt;em&gt;Person or Group&lt;/em&gt; field on your workflowProperties.Item, then you &lt;strong&gt;must&lt;/strong&gt; pass it an SPUser object! This is bizarre, because other types of list (e.g, the task list) you can pass it a &lt;strong&gt;string&lt;/strong&gt; and SharePoint will do the rest. I spent ages and all kinds of different things and always getting the “Invalid data has been used to update the list item. The field you are trying to update may be read only.” error. Annoying.&lt;/p&gt;</description>
      
    </item>
    
  </channel>
</rss>