Random Key Generator
public static string GetRandomPassword(int length)
{
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string password = string.Empty;
Random random = new Random();
for (int i = 0; i < length; i++)
{
int x = random.Next(1,chars.Length); //Don't Allow Repetation of Characters
if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i--;
}
return password;
}
}
Convert the String to Title Case Format
public static string toTitleCase(string text)
{
Return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text)
}
import namespace
using system.io;
public void PrintThis(Control ctrl)
{
StringWriter tmpStringWriter = new StringWriter();
System.Web.UI.HtmlTextWriter tmphtmlWrite = new System.Web.UI.HtmlTextWriter(tmpStringWriter);
//Declare Form
HtmlForm tmpform = new HtmlForm();
tmpform.Attributes.Add("runat", "server");
//Declare Page
Page tmpPage = new Page();
tmpPage.EnableEventValidation = false;
tmpPage.Controls.Add(tmpform);
//Add Form Control To Page
tmpform.Controls.Add(ctrl);
//Initialize page
tmpPage.DesignerInitialize();
//Render Page OutPut
tmpPage.RenderControl(tmphtmlWrite);
//Get Output string in String Varuable
string tmpstrHTML = tmpStringWriter.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(tmpstrHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
public static string GetRandomPassword(int length)
{
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string password = string.Empty;
Random random = new Random();
for (int i = 0; i < length; i++)
{
int x = random.Next(1,chars.Length); //Don't Allow Repetation of Characters
if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i--;
}
return password;
}
}
Convert the String to Title Case Format
public static string toTitleCase(string text)
{
Return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text)
}
Print output of single asp.net control
c#:import namespace
using system.io;
public void PrintThis(Control ctrl)
{
StringWriter tmpStringWriter = new StringWriter();
System.Web.UI.HtmlTextWriter tmphtmlWrite = new System.Web.UI.HtmlTextWriter(tmpStringWriter);
//Declare Form
HtmlForm tmpform = new HtmlForm();
tmpform.Attributes.Add("runat", "server");
//Declare Page
Page tmpPage = new Page();
tmpPage.EnableEventValidation = false;
tmpPage.Controls.Add(tmpform);
//Add Form Control To Page
tmpform.Controls.Add(ctrl);
//Initialize page
tmpPage.DesignerInitialize();
//Render Page OutPut
tmpPage.RenderControl(tmphtmlWrite);
//Get Output string in String Varuable
string tmpstrHTML = tmpStringWriter.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(tmpstrHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}