How to obtain SPUser object from values such as "27;#Morteza"?
Sometimes by fetching the list item of a field which is of type user, you may like to get the SPUser object of that user which is in string format.For example in task list the value of item["AssignedTo"] would we someting like "27;#Morteza".This string is actually showing us a user "morteza" with 27 as it's ID.
If you need to get to this users properties like InternalName,StaticName or LoginName then item["AssignedTo"] will do nothing for us.Instead you should take advantage of SPFieldUserValue:
SPFieldUserValue userValue = new SPFieldUserValue(SPContext.Current.web , item["AssignedTo"]);
SPUser userObject = userValue.User;
and now you can obtain any information for user such as LoginName:
userObject.LoginName
Thanks to Ali Kamrani for his tips on the topic.