Author Archive

October 10, 2008 1

Create PDF Forms using iTextSharp

By in Uncategorized

Generating PDF forms in .NET has always been somewhat messy and complicated. I’ve seen people convert raw HTML to PDF or adding and formatting form elements to a PDF doc in code behind, etc. All those methods are highly time consuming and tricky. Easiest way to create PDF Forms is by using iTextSharp (open source) [...]

Tags: ,

October 4, 2008 0

ADO.NET Data Access Template

By in Uncategorized

Here’s a basic ADO.NET data access template with a SqlCacheDependency. Just wanted to post this for my future reference. public static DataSet GetData(long itemID) { DataSet ds = new DataSet(); string cacheKey = Helpers.GetCacheKey(itemID); //Get a cache key unique to this method. if (HttpContext.Current.Cache[cacheKey] != null) { ds = (DataSet)HttpContext.Current.Cache[cacheKey]; } else { using (SqlConnection [...]

Tags: ,

September 26, 2008 0

Code Blocks Inside Master Pages

By in Uncategorized

Some time ago I kept getting this error in one of the projects I was working on: The Controls collection cannot be modified because the control contains code blocks (i.e. ). I spent quite some time trying to figure it out. Finally after hours of searching I found out that Code Blocks Inside Master Pages [...]

Tags: , ,

September 12, 2008 0

How to setup an asp.net website on localhost

By in Uncategorized

First lets start by setting up the site in IIS… 1.Open IIS by double-clicking on Control Panel->Administrative Tools->Internet Information Services 2.Right Click on Web Sites->Default Web Site 3.Click on Properties->Home Directory and choose the location of your website Now lets give the ASPNET account the appropriate permissions to access that directory… 4. Using My Computer [...]

Tags: ,

September 1, 2008 0

How To Clear All Items From Cache

By in Uncategorized

if (Cache.Count > 0) { string currentKey = string.Empty; System.Collections.IDictionaryEnumerator cacheContents = System.Web.HttpContext.Current.Cache.GetEnumerator(); Response.Write(string.Format(“Following {0} cache keys were cleared:”, Cache.Count)); while (cacheContents.MoveNext()) { currentKey = cacheContents.Key.ToString(); Response.Write(currentKey + “”); System.Web.HttpContext.Current.Cache.Remove(currentKey); } } else { Response.Write(“Nothing to clear. Cache is empty.”); }

Tags: ,

September 1, 2008 0

How To Load & Reference An Usercontrol From Code Behind

By in Uncategorized

First lets create a sample user control called MyControl for demonstration purposes public partial class _Controls_MyControl : System.Web.UI.UserControl { private string _myProperty; public string MyProperty { get { return _myProperty; } set { _myProperty = value; } } protected void Page_Load(object sender, EventArgs e) { } } Now register this control in the web.config <pages> [...]

Tags: ,

June 25, 2008 5

ASP.NET Inline Tags

By in Uncategorized

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 [...]

Tags:

May 6, 2008 0

How to easily parse HTML without RegEx

By in Uncategorized

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 [...]

Tags: , ,

April 23, 2008 0

How To Create A Random Fact Generator Using XML

By in Uncategorized

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 of [...]

Tags: ,

April 22, 2008 0

How to manipulate video in .NET using ffmpeg (updated)

By in Uncategorized

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 [...]

Tags: ,