<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: csharp code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 23:22:45 GMT</pubDate>
    <description>DZone Snippets: csharp code</description>
    <item>
      <title>Build GoogleSearchService.dll from GoogleSearch.wsdl</title>
      <link>http://snippets.dzone.com/posts/show/976</link>
      <description>To generate the C# stub source type:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;wsdl GoogleSearch.wsdl&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This will result in GoogleSearchService.cs.&lt;br /&gt;Compile with: &lt;br /&gt;&lt;code&gt;&lt;br /&gt;csc /target:library GoogleSearchService.cs&lt;br /&gt;(or mcs /target:library GoogleSearchService.cs for mono)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now you have the final stub assembly: GoogleSearchService.dll</description>
      <pubDate>Thu, 15 Dec 2005 00:38:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/976</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>How to work around the "double-click" problem</title>
      <link>http://snippets.dzone.com/posts/show/975</link>
      <description>This is a generic method to avoid "double-click" effect where a user click many times to validate. The button is hidden when the user clicks it. In order to not update all forms, the trick is applied to the Render event of the page.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;protected override void Render(HtmlTextWriter output) {&lt;br /&gt;    // Get normal html ouput&lt;br /&gt;    StringBuilder stringBuilder = new StringBuilder();&lt;br /&gt;    StringWriter stringWriter = new StringWriter(stringBuilder);&lt;br /&gt;    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);&lt;br /&gt;    base.Render(htmlWriter);&lt;br /&gt;    string html = stringBuilder.ToString();&lt;br /&gt;    // Enhance submit buttons&lt;br /&gt;    string onclick1 = "\"if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();";&lt;br /&gt;    string onclick2 = "\"this.style.display='none';";&lt;br /&gt;    html = html.Replace("onclick=" + onclick1, "onclick=" + onclick2 + onclick1.Substring(1));&lt;br /&gt;    // Render updated html&lt;br /&gt;    output.Write(html);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 15 Dec 2005 00:32:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/975</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Simple webform to test mail</title>
      <link>http://snippets.dzone.com/posts/show/906</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;%@ Page Language="C#" %&gt;&lt;br /&gt;&lt;%@ Import Namespace="System.Web.Mail" %&gt;&lt;br /&gt;&lt;script runat="server"&gt;    &lt;br /&gt;void btnSubmit_Click(Object sender, EventArgs e) {&lt;br /&gt;  MailMessage mail = new MailMessage();&lt;br /&gt;  mail.To = txtTo.Text;&lt;br /&gt;  mail.From = txtFrom.Text;&lt;br /&gt;  mail.Subject = txtSubject.Text;&lt;br /&gt;  mail.Body = txtMessage.Text;&lt;br /&gt;  mail.Priority = MailPriority.High;&lt;br /&gt;  mail.BodyFormat = MailFormat.Text;&lt;br /&gt;  SmtpMail.SmtpServer = txtSmtpServer.Text;&lt;br /&gt;  if (txtSmtpUsername.Text.Trim() != "") {&lt;br /&gt;    if (txtSmtpPassword.Text.Trim() != "") {&lt;br /&gt;      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");&lt;br /&gt;      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", txtSmtpUsername.Text);&lt;br /&gt;      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtSmtpPassword.Text);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  try {&lt;br /&gt;    SmtpMail.Send(mail);&lt;br /&gt;    Response.Write("OK!");&lt;br /&gt;  } catch (Exception ex) {&lt;br /&gt;    Response.Write("KO: " + ex.ToString());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;  &lt;head&gt;&lt;br /&gt;    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;&lt;br /&gt;    &lt;title&gt;Mail test&lt;/title&gt;&lt;br /&gt;  &lt;/head&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;    &lt;form runat="server"&gt;&lt;br /&gt;      &lt;ul&gt;&lt;br /&gt;        &lt;li&gt;Smtp Server : &lt;asp:TextBox id="txtSmtpServer" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;Smtp Username : &lt;asp:TextBox id="txtSmtpUsername" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;Smtp Password : &lt;asp:TextBox id="txtSmtpPassword" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;From : &lt;asp:TextBox id="txtFrom" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;To : &lt;asp:TextBox id="txtTo" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;Subject : &lt;asp:TextBox id="txtSubject" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;Message : &lt;asp:TextBox id="txtMessage" TextMode="MultiLine" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/li&gt;&lt;br /&gt;      &lt;/ul&gt;&lt;br /&gt;      &lt;asp:Button runat="server" id="btnSubmit" OnClick="btnSubmit_Click" Text="Send"&gt;&lt;/asp:Button&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 Nov 2005 21:30:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/906</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Get Week number (french culture)</title>
      <link>http://snippets.dzone.com/posts/show/856</link>
      <description>&lt;code&gt;&lt;br /&gt;public static int weekNumber(DateTime dt) {&lt;br /&gt;	CultureInfo culture = CultureInfo.CurrentCulture;&lt;br /&gt;	int intWeek = culture.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);&lt;br /&gt;	return intWeek;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 04 Nov 2005 21:39:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/856</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Convert String to Enum</title>
      <link>http://snippets.dzone.com/posts/show/824</link>
      <description>&lt;code&gt;&lt;br /&gt;enum EngineType {&lt;br /&gt;	unknow, &lt;br /&gt;	access, &lt;br /&gt;	db2, &lt;br /&gt;	mysql, &lt;br /&gt;	odbc, &lt;br /&gt;	oledb, &lt;br /&gt;	oracle, &lt;br /&gt;	postgre, &lt;br /&gt;	sqlserver&lt;br /&gt;}&lt;br /&gt;string cnxTypeString = "mysql";&lt;br /&gt;EngineType cnxTypeEngine = EngineType.unknow;&lt;br /&gt;if (Enum.IsDefined(typeof(EngineType), cnxTypeString)) {&lt;br /&gt;	cnxTypeEngine = (EngineType) Enum.Parse(typeof(EngineType), cnxTypeString, true);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 20 Oct 2005 17:15:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/824</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Algorithm for calculating the date of Easter Sunday</title>
      <link>http://snippets.dzone.com/posts/show/765</link>
      <description>&lt;code&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Algorithm for calculating the date of Easter Sunday&lt;br /&gt;/// (Meeus/Jones/Butcher Gregorian algorithm)&lt;br /&gt;/// http://en.wikipedia.org/wiki/Computus#Meeus.2FJones.2FButcher_Gregorian_algorithm&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name="year"&gt;A valid Gregorian year&lt;/param&gt;&lt;br /&gt;/// &lt;returns&gt;Easter Sunday&lt;/returns&gt;&lt;br /&gt;public static DateTime EasterDate(int year) {&lt;br /&gt;    int Y = year;&lt;br /&gt;    int a = Y % 19;&lt;br /&gt;    int b = Y / 100;&lt;br /&gt;    int c = Y % 100;&lt;br /&gt;    int d = b / 4;&lt;br /&gt;    int e = b % 4;&lt;br /&gt;    int f = (b + 8) / 25;&lt;br /&gt;    int g = (b - f + 1) / 3;&lt;br /&gt;    int h = (19 * a + b - d - g + 15) % 30;&lt;br /&gt;    int i = c / 4;&lt;br /&gt;    int k = c % 4;&lt;br /&gt;    int L = (32 + 2 * e + 2 * i - h - k) % 7;&lt;br /&gt;    int m = (a + 11 * h + 22 * L) / 451;&lt;br /&gt;    int month = (h + L - 7 * m + 114) / 31;&lt;br /&gt;    int day = ((h + L - 7 * m + 114) % 31) + 1;&lt;br /&gt;    DateTime dt = new DateTime(year, month, day);&lt;br /&gt;    return dt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Easter Monday = Easter Sunday + 1&lt;br /&gt;Ascension Day = Easter Sunday + 39&lt;br /&gt;Pentecost Sunday = Easter Sunday + 49&lt;br /&gt;Pentecost Monday = Easter Sunday + 50&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Tue, 27 Sep 2005 23:29:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/765</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Capitalization</title>
      <link>http://snippets.dzone.com/posts/show/705</link>
      <description>&lt;code&gt;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;&lt;br /&gt;public class MyClass {&lt;br /&gt;&lt;br /&gt;	public static void Main() {&lt;br /&gt;		string text = "the quick red fox jumped over the lazy brown DOG.";&lt;br /&gt;		System.Console.WriteLine("text=[" + text + "]");&lt;br /&gt;		string result = Regex.Replace(text, @"\w+", new MatchEvaluator(MyClass.CapText));&lt;br /&gt;		System.Console.WriteLine("result=[" + result + "]");&lt;br /&gt;		System.Console.ReadLine();	&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	static string CapText(Match m) {&lt;br /&gt;		string temp = m.ToString();&lt;br /&gt;		temp = char.ToUpper(temp[0]) + temp.Substring(1, temp.Length - 1).ToLower();&lt;br /&gt;		return temp;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;http://windows.oreilly.com/news/csharp_0101.html</description>
      <pubDate>Wed, 14 Sep 2005 20:58:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/705</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>yyyymmdd to DateTime</title>
      <link>http://snippets.dzone.com/posts/show/541</link>
      <description>&lt;code&gt;&lt;br /&gt;DateTime myDate;&lt;br /&gt;myDate = System.DateTime.ParseExact("20050802",&lt;br /&gt;                                    "yyyyMMdd",&lt;br /&gt;                                    System.Globalization.CultureInfo.InvariantCulture);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Tue, 02 Aug 2005 20:56:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/541</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>DateTime to yyyymmdd</title>
      <link>http://snippets.dzone.com/posts/show/540</link>
      <description>&lt;code&gt;&lt;br /&gt;string myString = myDate.ToString("yyyyMMdd");&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 02 Aug 2005 20:53:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/540</guid>
      <author>ms_michel (Michel)</author>
    </item>
    <item>
      <title>Set ValueToCompare at design time</title>
      <link>http://snippets.dzone.com/posts/show/524</link>
      <description>With DateTime, we have to convert value to its short date string representation :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;myCompareValidator.ValueToCompare = myDateTime.ToShortDateString();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Jul 2005 19:24:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/524</guid>
      <author>ms_michel (Michel)</author>
    </item>
  </channel>
</rss>
