Archive for the 'Programming' category
Wednesday, June 25th, 2008
There are all sorts of different inline tags, and I haven’t found a place that explains them all in one place, so here is the quick and dirty…
<% … %>
The most basic inline tag, basically runs normal code:
<% if (User.IsInRole(”admin”)) { %>
You can see this
<% } else { %>
You are no admin fool!
<%} %>
http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx
<%= … […]
Programming |
Tuesday, May 6th, 2008
I recently discovered an absolutely amazing HTML parsing library for .NET called HtmlAgilityPack. It completely takes away the pain of parsing complicated HTML with regular expressions.
Here’s a very simple example of what you could do with it - I’m just extracting inner HTML from any element inside a HTML file which has a css class […]
Programming |
Wednesday, April 23rd, 2008
This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.
XML: (Facts.xml)
<?xml version=”1.0″ encoding=”utf-8″ ?>
<facts>
<fact>
The numbers ‘172′ can be found on the back […]
Programming |
Tuesday, April 22nd, 2008
Based on the reader comments on my previous entry on this topic I was able to fix some of the issues that others were experiencing.
I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option […]
Programming |
Friday, April 18th, 2008
Recently I was involved in a project where I had to make heavy use of AJAX. I realized there are a few simple things you could do to improve performance.
1) Combine scripts
<ajaxToolkit:ToolkitScriptManager ID=”TSM1” runat=”Server”
EnablePartialRendering=”true”
CombineScriptsHandlerUrl=”~/CombineScriptsHandler.ashx” />
As the name of the property suggests, it will pretty much combine all the needed JS files into one which in […]
Programming |
Tuesday, April 8th, 2008
In my previous post about exception logging, I show how to log several different parameters related to the exception in the database. Request.Browser.Crawler is one of them and its used to track browser crawlers. It warrants its own separate entry since it requires some extra bit of setup in the web.config to get it to […]
Programming |
Tuesday, April 8th, 2008
This is a simple technique I use to log exceptions in all my web applications.
First lets start by adding the following to the web.config:
<appSettings>
<add key=”LogUnhandledExceptions” value=”true”/>
</appSettings>
Second, we add the following bit inside the Application_Error event of the Global.asax file. This will capture all the unhandled exceptions and log them into the database:
private static bool logUnhandledExceptions […]
Programming |
Saturday, March 29th, 2008
Recently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error - “Invalid Parameter Used” - whenever I tried […]
Programming |
Wednesday, March 12th, 2008
SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info - http://www.icsharpcode.net/OpenSource/SharpZipLib/
In the following example I’m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.
.
.
using System.IO;
using ICSharpCode.SharpZipLib.Zip
.
.
private void UnzipAndSave(HtmlInputFile objFileUpload)
{
ZipInputStream s = new ZipInputStream(objFileUpload.PostedFile.InputStream);
ZipEntry theEntry;
[…]
Programming |
Wednesday, March 12th, 2008
In this case I’m resizing the video and converting it to FLV format. For more ffmpeg commandline options - http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html
private void ConvertVideo(string srcURL, string destURL)
{
string ffmpegURL = “~/project/tools/ffmpeg.exe”;
DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Server.MapPath(ffmpegURL);
[…]
Programming |