I have this below code which will fetch loggedin UserID
System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
//networkID=User.
string strName = p.Identity.Name;
int start;
start = strName.IndexOf("\") + 1 ;
strName = strName.Substring(start, strName.Length - start);
But start = strName.IndexOf(“\”) + 1 ; throwing out error saying Newline in constant. The logged in username I get is domainName\username and I want to use only username. Please help
Try
IndexOf(@"\")orIndexOf("\\").