Posts Tagged ‘c#’

May 6, 2009 4

How to Parse Twitter Usernames, Hashtags and URLs in C# 3.0

By J in Uncategorized

Lately I’ve been working on my pet project called Twime. So as part of that project, I wanted to add the ability to parse URLs, usernames and hashtags from the user’s Twitter timeline. Here’s how I went about doing that:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

public static class HTMLParser
{
public static string Link(this [...]

Tags: , ,

February 20, 2009 0

Calculate Shipping Cost Using UPS OnLine Tools

By J in Uncategorized

Before using this code, all you need to do is register for an UPS OnLine Tools account and then apply for a XML Access key using your developer key which you will receive after creating an account. After you get your access key, just plug your username, password and the key into the highlighted line [...]

Tags: , ,

September 1, 2008 0

How To Clear All Items From Cache

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

May 6, 2008 0

How to easily parse HTML without RegEx

By J 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 class [...]

Tags: , ,

April 23, 2008 0

How To Create A Random Fact Generator Using XML

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

Tags: ,

April 22, 2008 0

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

By J 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 option [...]

Tags: ,

March 12, 2008 0

How to unzip files in .NET using SharpZipLib

By J in Uncategorized

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

Tags: ,

March 12, 2008 7

How to manipulate video in .NET using ffmpeg

By J in Uncategorized

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

Tags: ,

February 16, 2008 0

Event Driven Developement using ASP.NET & C#

By J in Uncategorized

Until recently I wasn’t entirely familiar with the concepts of Event Driven Programming, Event Bubbling, etc. Being a .NET developer I’ve been exposed to events and delegates but I never really understood the concept in its entirety. Somehow I had a hard time readily finding good sources online focusing on event driven programming especially using [...]

Tags:

January 16, 2008 1

C# Coding Standards and Best Programming Practices

By J in Uncategorized

I was reading a best practices document created by the DotNetSpider team which covered many aspects of programming in .NET. I was really impressed by it and I think its a very good reference document. So I’ve decided to make a series of posts where I’ll post sections of their document covering a specific topic.

Tags: ,