Adding app_offline.htm to the root of your .net application automatically shuts it down. Very nice for putting up a quick maintenance page.
All the junk I have in my head
Adding app_offline.htm to the root of your .net application automatically shuts it down. Very nice for putting up a quick maintenance page.
Regex.Replace(filePath, ".txt", ".zip", RegexOptions.IgnoreCase);
All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it:
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.
protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.
http://msdn.microsoft.com/en-us/library/ms173121.aspx
The only way I found to change the HtmlEncode property on a bound column when auto-generating the grid-view.
protected void grFeedHistoryView_RowDataBound(object sender, GridViewRowEventArgs e) { BoundField field = (BoundField)((DataControlFieldCell)e.Row.Cells[2]).ContainingField; field.HtmlEncode = false; }
private void InsertAndUpdate() { NorthwindDataContext db = new NorthwindDataContext(); //Insert a record Customer newCus = new Customer(); newCus.CustomerID = "YYYZZ"; newCus.CompanyName = "Company_Z"; db.Customers.InsertOnSubmit(newCus); db.SubmitChanges(); //Update a record Customer record = (from p in db.Customers where p.CustomerID == "12345" select p).SingleOrDefault(); Console.WriteLine(default(Customer)); if (record != default(Customer)) { record.CompanyName = "Company_A"; } db.SubmitChanges(); }
This code project helped me out a lot.
http://www.codeproject.com/Articles/19639/Implementing-IHierarchy-Support-Into-Your-Custom-C
Don’t recall where I found this but converts List to DataTable.
public static System.Data.DataTable ToDataTable<T>(this IList<T> data) { System.ComponentModel.PropertyDescriptorCollection props = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T)); System.Data.DataTable table = new System.Data.DataTable(); for (int i = 0; i < props.Count; i++) { System.ComponentModel.PropertyDescriptor prop = props[i]; table.Columns.Add(prop.Name); //table.Columns.Add(prop.Name, prop.PropertyType); } object[] values = new object[props.Count]; foreach (T item in data) { for (int i = 0; i < values.Length; i++) { values[i] = props[i].GetValue(item); } table.Rows.Add(values); } return table; }
Pieced this together from stackoverflow… http://stackoverflow.com/questions/2912476/using-c-sharp-to-check-if-string-contains-a-string-in-string-array/2912541#2912541
string stringToCheck = "text1"; string[] stringArray = { "text1", "testtest", "test1test2", "test2text1" };
This checks if stringToCheck contains any one of substrings from stringArray.
if(stringArray.Any(stringToCheck.Contains))
If you want to ensure that it contains all the substrings, change Any to All:
if(stringArray.All(s => stringToCheck.Contains(s)))
Here is a regular expression for credit card numbers.
string ccRegEx = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$";
Below is the regex code for U.S. and Canadian zip codes. I’m don’t remember where I found these but hopefully someone finds them useful.
string _usZipRegEx = @"^\d{5}(?:[-\s]\d{4})?$"; string _caZipRegEx = @"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$";