Get Name of Person Logged Into SharePoint - Agni Reddy
in

InfoPath Dev

Agni Reddy

Get Name of Person Logged Into SharePoint

Generally it's not possible to get the logged in username of the person logged into SharePoint. To do this we need to first create a file and query the modified name from the SharePoint form library for this file. Once we get the name we then delete this file. This document explains how to do this.

  1. Add a Sharepoint Submit data connection named SharePointSubmit to the solution.
  2. In the OnLoad code of the solution, add code to submit this form to SharePoint:

DAVAdapter sharePoint = (DAVAdapter)thisXDocument.DataAdapters["SharePointSubmit"]; 
sharePoint.Submit();

  1. Then follow the Query for Items in SharePoint Form Library Using GetListItems Web Method how to article to get the details of this form using GetListItems SharePoint Web service function.
  2. Add the following code into the FormCode.cs of the solution:

// Pass the GetlistItem node received from the previous step into this method.

private string getUserName(IXMLDOMNode getListItemsResult)

{

    string userName = getListItemsResult.selectNodes("//rs:data/z:row/@ows_Editor");

    // To get the Modified Username from the SharePoint Form Library.
    userName = userName.Substring(4);

    // "20;#" characters occur before user name. This method skips the mysterious characters.
    return userName;
}

  1. Now delete this file using the UpdateListItems SharePoint Web service function. Details on how to use this function are in the Delete File from SharePoint how to article.
  2. You can use this username where ever you need the logged in SharePoint user name.
Published Jun 28 2006, 05:05 PM by Agni Reddy
Filed under:

Comments

No Comments

About Agni Reddy

Agni is a Microsoft MVP. He began his InfoPath career in 2004 testing solutions developed at Qdabra™ Software and quickly transitioned to an InfoPath developer. He now has expertise developing complex InfoPath solutions. Agni holds a Master's degree in Information Systems.
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.