C# 2.0
Here is a very simple way to resize an image using a bitmap as a canvas and the graphics object as a the resizing tool. Don’t forget to reference System.Drawing. /// <summary>
/// Resizes an image from a source file to a destination file
/// the destination file will contain the exact image at the size specified
/// </summary>
/// <param name="sourceImagePath">the source image file that needs to be resized</param>
/// <param name="destinationImagePath">the destination path that the source
/// image file needs to be resized to</param>
/// <param name="width">the new width</param>
/// <param name="height">the new height</param>
static void ResizeImage(string sourceImagePath,
...
One of the most efficient and non-intrusive ways you can implement an intercepting procedure is via an HttpModule. An HttpModule simply receives every request going to or coming from IIS and it allows you to manipulate the content as you see fit and pass it along. I wanted to spit out the time it takes from receiving a request to writing the response on one or more web pages and there was no other better way of doing it except writing an HttpModule, it toke me all but 10mins. Here is the code, feel free to blow it up. ...
/// <summary>
/// using reflection to create an instance of a generic type
/// </summary>
/// <returns>T as the generic type</returns>
private static T GetNewObject()
{
try
{
return (T)typeof(T).GetConstructor(new Type[] { }).Invoke(new object[] { });
}
catch...
As my forever quest for simple & reusable code keeps growing, I stumble across some bottlenecks once in a while. Anyway, I have a simple class that is called "PopulateObjectFromFormRequest" and as descriptive as the name is, it does one simple yet helpful task. Given an object as a generic type I.e (user) and a web form as a parameter I.e (aspnetform), it will scan through all the controls of that web form and use reflection on the object and assign values to the object properties that matches controls from within the form. How does this help me? Well if I my...
Once you start building applications that run every so often for an undefined/unknown amount of time, its very possible that two processes may overlap. For example, if you have a schedule task that executes a console application every 5 mins, it is possible that very much possible that it will execute another before the previous one completes. So, how do we determine if a process is already running? So far I've seen three ways of doing it. Use the Singleton pattern Use Mutex Use System.Diagnostics (my preffered method) /// <summary>
/// Determines if this process is already running, if so it will kill itself.
/// </summary>
static void ExitIfRunning()
{
...
Ok, seriously, this debate must end! I strongly believe that changing a variable to a property is breaking a change! However, others feel otherwise. Update: Yes, this debate is not valid for C# 3.0, however, the question is intended for the earlier versions of C# which is still widely used.private string name;
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
How many times have you seen a similar snippet just like...
This is one of those "Yeah I've always seen people use it differently but I don't know why!" questions. Re-throwing exceptions can be misused, although it may not cause any harm to your application - there are multiple ways of re-throwing an exception, most likely for the purpose of bubbling it up to a higher level. Note to Java developers: It is different in your world. Lets look at how many ways we can use throw: throw throw ex throw new Exception(); You should not use #3 except if you are throwing a specific exception other...
These are the questions that I usually ask during an interview process with an applicant that is in for a technical assessment interview. These questions assumes that you are well rounded and full blown .NET Web Developer. A .NET web developer should at least know ASP.NET, C#/VB.NET and TSQL.
What are HttpModules and HttpHandlers, and what is the difference between the two?
What is the difference between CREATE PROC and CREATE PROCEDURE?
What is ViewState and what are its advantages and disadvantages?
...
As an IT Consultant with numerous number of projects that has to do with a lot of data which at the end of the day requires paging - I'm really tired of writing paging methods for every project. Therefore, on this nice beautiful Saturday I've decided that I'll knock out a paging control which I'll gladly call the Data Pager Control.
It's almost inevitable to get a project these days that doesn't require some kind of data management. The two major aspects of web development that takes the majority of my time are: UI and Data Access. I've taken upon...
A better and cleaner way for checking for an active internet connection. see http://blog.dotnetclr.com/archive/2007/08/30/Check... for the older version. 1: /// <summary> 2: /// Performs actions on the network 3: /// </summary> 4: public sealed class NetworkHandler 5: { 6: /// <summary> 7: /// Private constructor to prevent compiler from generating one 8: /// since this class only holds static methods and properties 9: /// </summary>...
Full C# 2.0 Archive
Next entries »