Archive for October, 2008

Send asynchronous mail using asp.net

Send mail is an important and common feature in asp.net. using system.net.mail namespace  we can send mail. In that article my main concert is to show how shall we send mail asynchronously, as for a bulk of mail sending asynchronous mail send is very important and asp.net have that feature in it.

I had written a wiki in asp.net on with code on  send asynchronous mail.

here you will get codes do send  asynchronous mail http://wiki.asp.net/page.aspx/536/send-asynchronous-mail-using-aspnet/


Read Full Post »

I was reading httpwebresponse data and get the basic data from the html data. So i need to remove all html tag, script tags, style tags from page to get original text data. So use a simple regular expression to remove tags. this regular expression was simple like that.

Regex.Replace(mainData,@”<scripts[^>]*>.*?</script>|<s*(?!/?(?:br?|i|p|u)b[^>]*>)[^>]*>”,””, RegexOptions.IgnoreCase | RegexOptions.Singleline) ;

I was working fine but i found that for some pages these are making problem specially problems are coming to remove javascript and styles from html data and data was not coming in a good format.

Finally I have got a very nice tool to do that . name of the tool is Html Agility .

this is a very nice features in html agility , it has libraires to convert html to xml, html to rss and html to text. I used html to text yo convert my httpresponse data to text.

in html agility you will find a class HTMLDocument.cs If you want to convert your webresponses then just add these codes in Load method, bacuase in load method this is reading html file from a local drive so to read webresponse use that code.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), OptionDefaultStreamEncoding);

Read Full Post »

Caching is a very important concept in programming . caching is a very nice technique to speed up processing. To increase performance of application caching is a great enhance.

One of my buddy razwan has written a very nice article on asp.net caching using cache dependency on file. You can follow this article to implement that in your applicaiton to speed it up.

here is the link ASP.NET Caching with Cache Dependency on a File

Read Full Post »

Wrapping text

Sometime we face problen to wrap text. this is a very easy solution to solve wrapping problem .

public string GetFormattedText(string str)
string[] parts = str.Split(new char[] { ‘ ‘ });
StringBuilder sb = new StringBuilder();
foreach (string s in parts)
sb.Append(” <wbr>”);
return sb.ToString();

In case of firefox its is more easier, just use white-space: -moz-pre-wrap in css style.

Read Full Post »