Sunday, December 9, 2012

How to delete/select absolutely all mail/message in a GMAIL label.

Few months ago I have subscribed at www.forums.asp.net site as it is a great place for DOTNET troubleshooting. Every day more than 100 mails are storing in my mail box. Varieties types of questions, suggestions etc are posting at that site. Great....

Last day I was swiping my Gmail. There was many spam, many junked mail. Suddenly I have noticed that in the "ASP.NET Forum" label I have got almost 90,000 mail message and I allocate 1GB of 10GB storage of GMAIL!!!

 I started deleting and after some minutes I realized that it is very time consuming job to delete 90,000 mails. When I select all mails then it only selects 100 mails of current page. After delete 100 mails then select again 100 mails and delete......

At last I have find a solution.

Step 1: First Select all mail of current page.
Step 2: Then select Select all XXX conversations in "LABEL" from the middle-top of mail list. 
Step 3: Then press delete. 


That's all....


Sunday, December 2, 2012

My CHM file does not display its content!!!

After opening a CHM formatted file sometimes we see this message "This Program cannot display the webpage" instead of the content. 


The program cannot display the webpage


This problem is so common. and the solution is also simple.


Just remove the # or & or ? or +  character from the chm file name and/or folder and/or directory name. Because these characters have special meaning.


like:

if my chm file name is "c# book" then replace # character with other or remove # character.
again, if my chm file is in "F:/ASP and C#" directory then also replace # character with other or remove # character.



Happy Reading........



Wednesday, October 31, 2012

AppendLine method of StringBuilder class object doesn't work.

In ASP.NET AppendLine method of a StringBuilder class object does not put a new line if I show the result in asp:label control.

Here is the code snippet that I have tried - 



aspx page:-



<form id="form1" runat="server">
    <div>
        <asp:Label ID="lblResult" runat="server">          </asp:Label>
    </div>
</form>

cs code:-



protected void Page_Load(object sender, EventArgs e)
    {

        StringBuilder output = new StringBuilder();

        string[] str = { "AB", "BC", "CD", "DE" };
        foreach (string s in str)
        {
            output.AppendLine(s);
        }
        lblResult.Text = output.ToString();

    }

Output:-

AB BC CD DE


I have tried Environment.NewLine also. but failed.


At last I have found the solution: <br/> - as HTML respects this tag only. neither \n nor \r\n



So, after correction the code

            output.Append(s + "<br/>");

I have got my desired Output:

AB
BC
CD
DE

Thursday, September 27, 2012

Wednesday, September 19, 2012

Get Inner most exception


Lets consider a simple example.

We have a static void Main() method which is the entry point of our application.
From static void Main() we call a method named AMethod()
And AMethod() intern calling an another method AMethod1().
Now lets say AMethod1() unfortunately raises an exception which is sent to AMethod() and same is propagated to Main() function.





Look at the following line of code.


class Program
{
static void Main(string[] args)
{
try
{
AMethod();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}

private static void AMethod()
{
try
{
AMethod1();
}
catch (Exception ex)
{
throw new Exception("A Method", ex);
}
}

private static void AMethod1()
{
throw new Exception("Exception from A Method 1.");
}
}


Now, what will happen if you run the code? You will see that the output is "A Method"
Which is the exception message of AMethod() – which is not original error message. But as a developer our expected message is "Exception from A Method 1." Of AMethod1() – which is disguised by AMethod().

To avoid this situation the solution is GetBaseException() method which belongs to the Exception class and “returns the System.Exception that is the root cause of one or more subsequent exceptions.” – means the error from the main source which will not be omitted by another method.



class Program
{
static void Main(string[] args)
{
try
{
AMethod();
}
catch (Exception ex)
{
Console.WriteLine(ex.GetBaseException().Message.ToString());
}
}

private static void AMethod()
{
try
{
AMethod1();
}
catch (Exception ex)
{
throw new Exception("A Method", ex);
}
}

private static void AMethod1()
{
throw new Exception("Exception from A Method 1.");
}
}