Wednesday, June 27, 2007

Useful .Net stuff often overlooked

Ok, I need to write it down somewhere, the article has a lot of explanations, and I just want to record classes because I know what they are, but I will forget later.

The article is here: http://haacked.com/archive/2007/06/13/the-most-useful-.net-utility-classes-developers-tend-to-reinvent.aspx

Stuff to remember:

Combine path:
public string GetFullPath(string filename)
{
string folder = ConfigurationManager.AppSettings["somefolder"];
return System.IO.Path.Combine(folder, filename);
}
Get folder location:
someFolderPath + Path.DirectorySeparatorChar;
Get just the file name:
string fileName = Path.GetFileName(fullPath);
Get absolute path from virtual:
string path = VirtualPathUtility.ToAbsolutePath("~/Controls/Test.ascx");
Get new line separator (really neat one!) Environment.NewLine;

From comments:

Check if var is a number: Double.TryParse or Int.TryParse

Timing execution (not sure, but that's what it sounds like from the comment):
System.Diagnostics.Stopwatch

Query string: HttpUtility.ParseQueryString
Raw URL: HttpContext.Current.Request.RawUrl; (MSDN)

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home