Codigos Fonte, Artigos e Dicas
C# Dicas
Criptografar senha
23/06/09
public static class Seguranca
{
public static string CripitografaSenhaHASH(this string Senha)
{
Procurar serviço no Windows
23/06/09
//função que retorna se o serviço existe no windows ou nao
public string findService(string s)
{
string s3 = null;
try
{
ServiceController[] services;
services = ServiceController.GetServices();
for (int i = 0; i < services.Length; i++)
{
if (services[i].ServiceName == s)
{
s3 = "Found";
break;
}
}
}
catch (Exception x) { }
if (s3 == null)
return s3 = "Not Found";
else
return s3;
}
Limpar todos os TextBox de uma vez
22/06/09
private void limparControles()
{
foreach (Control cItem in this.Controls)
{
//A group box is found
if (cItem is GroupBox)
{
//Loop through all the group box components
foreach (Control cSubItem in cItem.Controls)
{
if (cSubItem is GroupBox)
{
foreach (Control cSubItem3 in cSubItem.Controls)
{
if (cSubItem3 is TextBox || cSubItem3 is MaskedTextBox)
{
cSubItem3.Text = "";
}
}
}
else
{
//If its a label of text box disable it
if (cSubItem is TextBox || cSubItem is MaskedTextBox)
{
cSubItem.Text = "";
}
}
}
}
}
}
Retornar IP de Host com C#
22/06/09
private String pegaIP(string hostName)
{
String s = "";
IPAddress[] addressList = Dns.GetHostByName(hostName).AddressList;
for (int i = 0; i < addressList.Length; i++)
s += addressList[i].ToString() + "\n";
return s;
}
Enviar e-mail com C#
22/06/09
public void enviarEmail(string assunto, string corpo)
{
//create the mail message
MailMessage mail = new MailMessage();