Archive for the ‘Uncategorized’ Category

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: ,

March 29, 2008 1

The Mysterious “Invalid Parameter Used” Error

By in Uncategorized

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

Tags: ,