"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Sunday, January 9, 2011

Random hexadecimal Numbers

Hi ,
2day i'm showing u some creating random hexadecimal numbers
 Code:

                Random _random = new Random();
                int i = 0;
                string _randomValue = string.Empty;
                for (i = 0; i < 100; i++) // Set the count here
                {
                    _randomValue = _randomValue +" , "+ _random.Next().ToString("X");
                }
                lbl_ErrMsg.Text = _randomValue.ToString();




Have a nice day... 'N happy Coding :)

Friday, January 7, 2011

Reverse Of a string In c#

Hi, 
2day I'm showing a string in reverse
Code

                string _reverse = "Simplyasp.blogspot.com";
                char[] _printArray = _reverse.ToCharArray();
                Array.Reverse(_printArray);
                lbl_Message.ForeColor = System.Drawing.Color.Red;
                lbl_Message.Text = _reverse.ToString() + " Reverse : " +(new       string(_printArray))+"";

Result

          Simplyasp.blogspot.com 

Reverse : moc.topsgolb.psaylpmiS




Have a nice day... 'N happy Coding :)

Thursday, January 6, 2011

Maintaining error log

Here I am simplfying error log implementaiton.
To maintain error log its good to have log for each day for a better review .
so here we will create log file everyday , and when file already exist will append error entry in to it.
For that create one class and write following method....

C#
Add this 2 Namespace
using System.IO;

using System.Globalization;

and the Rest of game will be handled by this class

public static void WriteError(string errorMessage)
    {
        try
        {
            //Specify path where log file to be created
            string logfilePath = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
            if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
            {
                File.Create(System.Web.HttpContext.Current.Server.MapPath(logfilePath)).Close();
            }
            using (StreamWriter wrtr = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
            {
                wrtr.WriteLine("\r\nLog Entry : ");
                wrtr.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
                string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                ". Error Message:" + errorMessage;
                wrtr.WriteLine(err);
                wrtr.WriteLine("__________________________");
                wrtr.Flush();
                wrtr.Close();
            }
        }
        catch (Exception ex)
        {
            WriteError(ex.Message);
        }
    }





Have a nice day... 'N happy Coding :)