Here’s a code snippet of parsing a typical WordPress RSS feed using LINQ. Note, we have to skip the first image from the media element since that’s usually a gravatar of the author. Everything else is pretty straight forward. private void BindBlogFeed() { XDocument doc = XDocument.Load(“http://blogworkseverytime.wordpress.com/feed/”); XNamespace content = “http://purl.org/rss/1.0/modules/content/”; XNamespace media = “http://search.yahoo.com/mrss/”; [...]
Posts Tagged ‘c#’
How to Parse Twitter Usernames, Hashtags and URLs in C# 3.0
By J in UncategorizedLately 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 { [...]
Calculate Shipping Cost Using UPS OnLine Tools
By J in UncategorizedBefore 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 [...]
How To Clear All Items From Cache
By J in Uncategorizedif (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.”); }
How to easily parse HTML without RegEx
By J in UncategorizedI 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 [...]
How To Create A Random Fact Generator Using XML
By J in UncategorizedThis 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 [...]
How to manipulate video in .NET using ffmpeg (updated)
By J in UncategorizedBased 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 [...]
How to unzip files in .NET using SharpZipLib
By J in UncategorizedSharpZipLib 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 [...]
Tags: c#, sharpziplib
How to manipulate video in .NET using ffmpeg
By J in UncategorizedIn 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); startInfo.Arguments = string.Format(“-i \”{0}\” -s 368×216 -aspect 1.7777 \”{1}\”", srcURL, destURL); startInfo.WorkingDirectory = [...]
Event Driven Developement using ASP.NET & C#
By J in UncategorizedUntil 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: c#