Friday, November 28, 2008

How to get the detail associated with the current user using C# (.NET)

Temp file name

String sFile;

sFile = Path.GetTempFileName();

Console.WriteLine("Temporary File " + sFile);

//Store the Values Temporarily in Temp file

StoreVar(sFile);


Temporary folders Name


string sPath;

sPath = Path.GetTempPath();

Console.WriteLine("Temporary Path := " + sPath );


IsPathRooted method of Path class returns a value indicating whether the specified path string contains absolute or relative path information


if (Path.IsPathRooted(@"c:\temp\") == true)

{

Console.WriteLine("Path is absolute");

}

else

{

Console.WriteLine("Path is relative");

}
To retrieve the logical MyDocuments use the following


Console.WriteLine("MyDocuments := " + Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments));

To retrieve the logical desktop use the following


Console.WriteLine("Desktop := " + Environment.GetFolderPath( Environment.SpecialFolder.Desktop));

Cookies folder (FullName) can be retrieved using the following snippet

Console.WriteLine("Cookies := " + Environment.GetFolderPath( Environment.SpecialFolder.Cookies ));


ApplicationData is the directory that serves as a common repository for application-specific data for the current roaming user. It can be retrieved using


Console.WriteLine("ApplicationData := " + Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData));

How to get the network domain name associated with the current user using C# (.NET)

Console.WriteLine("Domain Name := " + Environment.UserDomainName );

No of processors in the given machine can be retrieved by

Console.WriteLine("ProcessorCount := " + Environment.ProcessorCount );

Retrieve user name using .NET / How to get user name using C#

The following code will get the user name of the computer



Console.WriteLine("User Name := " + Environment.UserName);


Get Computer Name using .NET (C#)


Console.WriteLine("Machine Name := " + Environment.MachineName);

No comments: