ads

Sunday, July 19, 2009

Fabonacci Function c#










1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.


static void fibonacci(int x)
{
int y = 0, z = 1, total;

for (int i = 0; i < x; i++)
{
total = y + z;
Console.WriteLine(total);
y = z;
z = total;

}
}

Tuesday, June 23, 2009

Prevent a Class to be inherited C#

The sealed can be used to prevent a class to be inherited.

sample:
    sealed class FileClass
    {
        sealed FileClass(string filepath)
        {
            Filepath = filepath;
        }
   
        private string _filepath;
        public string Filepath
        {
            get { return _filepath;}
            set { _filepath = Filepath; }
        }
    }

Thursday, April 16, 2009

Display All Server Files in Server using C# and ASP.NET

DirectoryInfo di = newDirectoryInfo(Server.MapPath("/"));

FileInfo[] fi = di.GetFiles();

fi = di.GetFiles("*.*");

foreach (FileInfo fi1 in di.GetFiles())

{

Response.Write( fi1.FullName.ToString());

Response.Write("<br />");

}

Wednesday, April 8, 2009

Cross-Page Posting ASP .NET

Make 2 forms name it page1.aspx and page2.aspx

on page1.aspx:

Add a TextBox and Button Control

Go to the Button Control Properties and set the PostbackUrl = "~/page2.aspx"

on Page2.aspx:

Add a Label Control and on the Page_Load Event add this following code.

protectedvoidPage_Load(objectsender, EventArgs e)

{

if (PreviousPage != null)

{

if (PreviousPage.IsCrossPagePostBack == true)

{

Label1.Text = "Cross-page post.";

TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1");

this.Title = tb.Text;

}

}

else

{

Label1.Text = "You are not allowed to access this page!";

}

}

Google Search