Hi, friends
I have created infopath browser-enabled forms and uploaded them to
sharepoint server, but there is one function not working, that is to get the
current user who is using the forms.
I am using Infopath 07 and MOSS 07
I implemented it refering to this article from Infopath Team Blog,
Get the User Profile through MOSS Web Services
http://blogs.msdn.com/infopath/archive/2007/03/07/get-the-user-profile-through-moss-web-services.aspx
Following is my code, when I test it in console app, it works fine
and return my domain id, but when I put it in web service and invoke it, it
returns nothing.
[Code]
public static string CurrentUserName
{
get
/*{
System.Security.Principal.IPrincipal _User;
_User = System.Web.HttpContext.Current.User;
System.Security.Principal.IIdentity _Identity;
_Identity = _User.Identity;
string _Value;
//_Value = _Identity.Name;
_Value = _Identity.Name.Substring(_Identity.Name.IndexOf(@"\") + 1);
return _Value;
}*/
{
ProfileService.UserProfileService profileService =
new ProfileService.UserProfileService();
profileService.UseDefaultCredentials = true;
ProfileService.PropertyData[] userProps = null;
try
{
// Passing null to this method returns the profile of the
current user.
userProps = profileService.GetUserProfileByName(null);
}
catch { }
if (userProps == null
|| userProps.Length == 0)
{
return null;
}
string userName;
userName = userProps[1].Values[0].Value.ToString();
return userName.Substring(userName.IndexOf(@"\") + 1);
}
/*{ return System.Environment.UserName.ToString();
}*/
}
[/Code]
Anyone can help with this problem? really struggling to find the
solution these days...