CodeKeep C# Feed Gennaio 1st, 2009
Description: Create Instance System.Diagnostics.Process using new for processname Variable, Define string for cmd line like you type in runbox, use System.Diagnostics.Process.Start arg1 open command win, arg2 is string where /c runs & term win & SAVEpath-filename ext
Link: http://www.codekeep.net/snippets/422f7760-90f0-44e5-b51e-83cc7be7ac51.aspx
System.Diagnostics.Process process1;
process1 = new System.Diagnostics.Process();
//Do not receive an event when the process exits.
process1.EnableRaisingEvents = false;
//regTest file ExtenderProvidedPropertyAttribute works in Region, txt, rtf
//The "/C" Tells Windows to Run The Command then Terminate
string strCmdLine;
strCmdLine = "/C regedit.exe /e C:\\Users\\JohnnyL\\Desktop\\RegTest1.rtf";
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
process1.WaitForExit();
process1.Close();

CodeKeep C# Feed Dicembre 28th, 2008
->
CodeKeep C# Feed Dicembre 24th, 2008
Description: Liest Datei ein
Link: http://www.codekeep.net/snippets/cca5268e-3422-42c4-9b65-0fada846faff.aspx
var of = new OpenFileDialog();
of.InitialDirectory = cbLaufwerke.Text;
of.Filter = "all files (*.*)|*.*|txt files (*.txt)|*.txt|html files (*.htm,*.html)|*.htm;*.html";
of.FilterIndex = 1;
of.RestoreDirectory = true;
if (of.ShowDialog() == DialogResult.OK)
{
txtBox2.Text = of.FileName;
}

CodeKeep C# Feed Dicembre 23rd, 2008
CodeKeep C# Feed Dicembre 22nd, 2008
Description: Com sample
Link: http://www.codekeep.net/snippets/e093be78-1d5a-4a46-ac6e-64de6d2557aa.aspx
Type objTypeWord = Type.GetTypeFromProgID("Word.Application");
object objWord = Activator.CreateInstance(objTypeWord);
objTypeWord.InvokeMember("Visible", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.SetProperty ,
null,
objWord,
new object [] {true });

CodeKeep C# Feed Dicembre 21st, 2008
Description: Check credentials for a given user
Link: http://www.codekeep.net/snippets/fa68958b-157d-4a94-9cbb-2217a7c569cb.aspx
/// <summary>
/// Check credentials when blog user signs in
/// </summary>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <returns>Boolean value</returns>
public static bool checkCredentials(string username, string password)
{
string strSQL = "SELECT password,salt FROM tblUsers WHERE username=@username";
SqlConnection objConn = new SqlConnection(connString);
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
objCmd.Parameters.AddWithValue("@username", username);
string storedPassword = string.Empty;
string salt = string.Empty;
string givenPassword = string.Empty;
bool flag = false;
try
{
objConn.Open();
SqlDataReader sdr = objCmd.ExecuteReader();
if (!sdr.Read())
{
flag = false;
}
else
{
storedPassword = (string)sdr["password"];
salt = (string)sdr["salt"];
givenPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(salt + password, "SHA1");
flag = (storedPassword == givenPassword);
}
}
catch { }
finally
{
objConn.Close();
}
return flag;
}

CodeKeep C# Feed Dicembre 21st, 2008
Description: Check if email is in correct format
Link: http://www.codekeep.net/snippets/ec8b378f-1b7c-4dfe-9366-13f3da8d97c4.aspx
/// <summary>
/// Check if email is in correct format
/// </summary>
/// <param name="email"></param>
/// <returns>True if email is correct, false if not</returns>
public static bool CheckEmail(string email)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
//string strRegex = @"^(([^<>()[\]\\.,;:\s@\""]+"
// + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
// + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
// + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
// + @"[a-zA-Z]{2,}))$";
Regex re = new Regex(strRegex);
return re.IsMatch(email);
}

CodeKeep C# Feed Dicembre 19th, 2008
CodeKeep C# Feed Dicembre 19th, 2008
CodeKeep C# Feed Dicembre 16th, 2008
Description: Forms Authentication
Link: http://www.codekeep.net/snippets/7a4ad0da-08a5-46ca-8077-7a8e2713514a.aspx
protected void btnLogin_Click(object sender, EventArgs e)
{
AdminUser objAdminUser = new AdminUser();
objAdminUser.UserName =txtUserName.Text.Trim();
objAdminUser.Password = txtPassword.Text.Trim();
if (objAdminUser.AdminLoginUserValidate() != -100)
{
if (objAdminUser.UserID > 0)
{
// Create the authentication ticket
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
objAdminUser.UserID.ToString(), // user id
DateTime.Now, // creation
DateTime.Now.AddMinutes(60),// Expiration
false, // Persistent
objAdminUser.UserName + "," + objAdminUser.FirstName); // UserName and Fill Name
// Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
// Create a cookie and add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
// Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
//if there is a previous url to redirect them to
FormsAuthentication.RedirectFromLoginPage(objAdminUser.UserID.ToString(), false);
//if (Request.QueryString["ReturnUrl"] == null)
//{
// Response.Redirect("Welcome.aspx");
//}
//else
//{
// Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
//}
}
}
else
{
lblMsg.Text = "Invalid username and password.";
ModalPopupExtender2.Show();
}
}
In Web.congig
<authentication mode="Forms">
<forms name="SMGR" loginUrl="login.aspx" defaultUrl="welcome.aspx" timeout="1" protection="All" path="/"/>
</authentication>
Impliment in page:
bool IsAttribute = false;
public void CheckAuthentication()
{
if (!Context.User.Identity.IsAuthenticated)
{
string strRedirectURL = Server.UrlEncode(Context.Request.ServerVariables["URL"]);
Context.Response.Redirect("Login.aspx?ReturnUrl=" + strRedirectURL);
}
}
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthentication();
}
