Saturday 12 November 2011

How to Print Star in C#

Write the program in C# for print the
                  *
                 **
                ***
               ****
              *****
----------------------------------------
the program is ..
using System;


    class Class1
    {

        static void Main()
        {

            Console.WriteLine("Enter the value for print  the star ");

            int k = int.Parse(Console.ReadLine());

            int n = k - 1;

            int x = 2 * n + 1;

            for (int p = 0; p <= n; p++)
            {

                for (int j = k - 1; j >= 0; j--)
                {

                    Console.Write(" ");

                }

                for (int i = 0; i <= (x - 2 * (k - 1)); i++)
                {

                    if (i % 2 == 1)
                    {

                        Console.Write("*");

                    }

                    else
                    {

                        Console.Write(" ");

                    }

                }

                Console.WriteLine();

                k--;

            }

            Console.ReadLine();

        }

    }
Hope this will help you
Thanks
ROHIT SRIVASTVA




Tuesday 8 November 2011

How to upload file in Server fron client side

Hi guys some time question arise that how to upload image on server.

there are two technique

1. upload image in sqlserver which is not in actual form it is in byte form .

2. upload image path in SQL Server and image is upload in Server .

here we write the code for upload file in server and path save in sql server

Database structure :
========================================================================
Create Database uploadfile

use uploadfile

Create table upload
(
id int identity(1,1),
imgpath varchar(100)
)

Now Create the Store Procedure ..

Create proc usp_ins_uploadfile
@path varchar(100)
AS
insert into upload values(@path)

========================================================================

Lets start the code open the new website make the folder where u want to save your file or image.i make the folder which name is uploadfile .

below is the design part

<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:FileUpload ID="fupUpload" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>

</div>
</form>

in above there are file upload control and one submit button .
-----------------------------------------------------------------------------
below is the cs code

private string path = HttpContext.Current.Request.PhysicalApplicationPath + "uploadfile";
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
#region
//this code is used for the save the image
Random randomno = new Random();
int imageid1 = randomno.Next(0, 1000000);
string strpic = fupUpload.FileName;
if (strpic != "")
{
ViewState["logopath1"] = imageid1.ToString() + fupUpload.FileName.ToString();
fupUpload.PostedFile.SaveAs(path + "/" + ViewState["logopath1"]);
}
else
{
ViewState["logopath1"] = "";
}
#endregion
#region *this code is upload the file path in Server*
int result = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myCon"].ToString());
SqlCommand cmd = new SqlCommand("usp_ins_uploadfile", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@path", ViewState["logopath1"]);
result = cmd.ExecuteNonQuery();
if (result > 0)
{

}
else
{

}
#endregion
}

Description: In this code i declare the path which have the server path . after that wirte the code in button submit click .
firstly we genrate the random no this is because if file name is same then it override the file or image .
for example we upload image which name is rohit.png then fine this is save into our application folder .
but when again we upload another file or image which name is same like rohit.png then it replace the
previous image or file.in this code i divide the code in two part first region is save the data in folder
and second one is save the path in the database .

Hope this will help you
ROHIT SRIVASTAVA

Friday 4 November 2011

Computer Magic

Go to google.com and type below line . see what happen 
do a barrel roll
and press enter.
===========================================
2.
Open Microsoft Word and type

=rand (200, 99)

And then press ENTER
Then see the magic...

3.. Go to Goolgle and type TILT and Press enter 
see the magic

hope you have learn something new 
Thanks 
ROHIT SRIVASTVA