C# 3.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...
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?
...
If for some reason you need to send mail via the Google GMail SMTP server, here is how you do it. Keep in mind that the connection has to be secured and it's using an unusual port. If you have a firewall, you may want to do some re-configuration. 1: int port = 587; 2: string userName = "myemail@gmail.com"; 3: string password = "password"; 4: 5: try 6: { 7: MailMessage message = new MailMessage(); 8:...
Ok, I've been asked one too many times about how to convert a month int value to a short or long month name - so here goes nothing. 1: /// <summary> 2: /// Start program 3: /// </summary> 4: /// <param name="args">Arguaments not required</param> 5: static void Main(string[] args) 6: { 7: for (int month = 1; month < 13; month++) 8: { 9: ...
I spent a few hours yesterday trying to copy nodes from one xml document to another. The problem is this - there is a transport tool that transport XML documents from one server to the other and it works well, however, if the XML document(s) is large say over 15mb the transport tool fails. While trying not to rewrite the code, I decided that the most efficient way to solve the problem is to split the xml file in multiple files (chunks). The format of the document should remain the same and the 7 headers should be included in all chunks...
Full C# 3.0 Archive
Next entries »