Pages

Subscribe:

Ads 468x60px

Thursday, May 31, 2012

how to upload photo or picture in asp.net using c#

In this web programming tutorial we will learn that how we can upload a picture or photo in asp.net using c#. just copy and paste below code in you .cs file.
protected void btn_upload_Click(object sender, EventArgs e)
    {
        imageflag = 1;
 
        if (!FileUpload_image.HasFile)
        {
            Alert.Show("No file for uploading");
            return;
        }
        if (FileUpload_image.HasFile)
        {
            //string imagetype = FileUpload_image.PostedFile.ContentType;
            string[] acceptedTypes = new string[] 
            { 
                "image/bmp", 
                "image/jpeg", 
                "image/tiff", 
                "image/gif", 
                "image/png"
                     };
 
            if (!acceptedTypes.Contains(FileUpload_image.PostedFile.ContentType))
            {
                Alert.Show("This is not image file");
                return;
            }
            Bitmap image = ResizeImage(FileUpload_image.PostedFile.InputStream, 84, 118);
            string imagename = Guid.NewGuid().ToString();
            image.Save(Server.MapPath("~/Pictures/") + imagename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            Img_Employee.ImageUrl = "~/Pictures/" + imagename + ".jpg";
            image_path = "~/Pictures/" + imagename + ".jpg";
        }
 
 
    }
    private Bitmap ResizeImage(Stream streamImage, int maxWidth, int maxHeight)
    {
        Bitmap originalImage = new Bitmap(streamImage);
        int newWidth = originalImage.Width;
        int newHeight = originalImage.Height;
        double aspectRatio = (double)originalImage.Width / (double)originalImage.Height;
 
        if (aspectRatio <= 1 && originalImage.Width > maxWidth)
        {
            newWidth = maxWidth;
            newHeight = (int)Math.Round(newWidth / aspectRatio);
        }
        else if (aspectRatio > 1 && originalImage.Height > maxHeight)
        {
            newHeight = maxHeight;
            newWidth = (int)Math.Round(newHeight * aspectRatio);
        }
 
        return new Bitmap(originalImage, newWidth, newHeight);
    }

how to Upload Image or file on FTP in Asp.net using c#

In this web programming tutorial we will learn that how we can Upload Image or file on FTP in Asp.net File Uploader using c#.

copy the below code in your .cs file.

public void ftpfile(string ftpfilepath)
 {
     string ftphost = "your domain name ";
     //here correct hostname or IP of the ftp server to be given  
 
     string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
     FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
     ftp.Credentials = new NetworkCredential("your Domain", "Password");
     //userid and password for the ftp server to given  
 
     ftp.KeepAlive = true;
     ftp.UseBinary = true;
     ftp.Method = WebRequestMethods.Ftp.UploadFile;
      
     // Resize Image is function to resize the image 
     System.Drawing.Image img1 = 
         ResizeImage(FileUpload1.PostedFile.InputStream, 84, 118);
 
     // Convert the image into bytes Array;
     byte[] buffer = ImageToByte(img1);
  
     // Send the image file in form of bytes
     Stream ftpstream = ftp.GetRequestStream();
     ftpstream.Write(buffer, 0, buffer.Length);
     ftpstream.Close();
}

Saturday, May 26, 2012

how to disable right click using jquery

In this web programming tutorial we will learn that how we can prevent right click functionality in browser (this code snipit will work in all browsers).


    
    
    





how to create Tab menu widget using jquery

In this web programming tutorial we will learn that how can use jquery tabs widget using jquery UI.


    
    
    
    

    


    

This is tab one data.

This is tab two data.

This is tab three data.


how to generate image button dynamically in asp.net using c#

In this web programming tutorial we will learn that how we can create an image button dynamically in asp.net using c#. see the below code and put it in your .cs file in page load event.
protected void Page_Load(object sender, EventArgs e)
    {
        ImageButton imgBtn;
        imgBtn = new ImageButton();
        imgBtn.Attributes.Add("onclick", "javascript:return false;");
        imgBtn.ImageUrl = "~/sample.jpg";
        imgBtn.ID = "img_Tooltip";
        imgBtn.ToolTip = "www.web-healer.blogspot.com";
        imgBtn.CssClass = "img_tooltip_Style";
        imgBtn.Height = 50;
        imgBtn.Width = 100;
        form1.Controls.Add(imgBtn);
    }

Thursday, May 24, 2012

how to add text to image in asp.net using c#

In this web programming tutorial we will learn that how we can add some text on an image in asp.net using c#.just copy and page the code and add it in your .cs file.
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System;

public partial class About : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string inputImage = @"E:\color.jpg";
        string outputImageFilePath = @"E:\Resultimage.jpg";
        string textToDisplayOnImage = "www.webhealer.blogspot.com/";

        Bitmap imageInBitMap = new Bitmap(inputImage);
        Graphics imageGraphics = Graphics.FromImage(imageInBitMap);

        //Set the alignment based on the coordinates 
        StringFormat formatAssignment= new StringFormat();
        formatAssignment.Alignment = StringAlignment.Near;
        
        //Here we are going to assign the font color
        Color assignColorToString = System.Drawing.ColorTranslator.FromHtml("#000000");

        //Assigning font size, font family, position of the text to display and others.
        imageGraphics.DrawString(textToDisplayOnImage, new Font("Times new Roman", 8, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(100, 150), formatAssignment);

        //saving in the computer
        imageInBitMap.Save(outputImageFilePath);
    }
}

Monday, May 21, 2012

how to use span tag on a web page using html

In this web programming tutorial we will learn about span tag by using it on a web page using html.

span tag is used to provide an additional structure to an html document. It is used to group and apply style sheet to inline elements of a web page. it can be used to gave characteristics to specific part of other elements.

below is the code example how to use spam tag.

This is a paragraph this is a paragraph this is a paragraph

this is a paragraph

output

This is a paragraph this is a paragraph this is a paragraph

this is a paragraph


how to use div tag on a web page using html

In this web programming tutorial we will learn that how we can use div tag in an html document or in a web page.

div tag is normally used to define a section in an html document or in a web page div tag is a pair tag and must be used a closing tag in order to complete the tag

this is div tag
output
this is div tag

how to use font tag in html

In this web programming tutorial we will learn that how we can use font tag in an html document or in a web page.
 this text is with Verdana font 
 this text is with arial font 
 this text is with helvitica font 
 this text is with impact font 
this text is with Verdana font
this text is with arial font
this text is with helvitica font
this text is with impact font

how to use different format text in html

In this web programming tutorial we will learn that how we can use different type of text format in an web page or in an html document. see the below code.

here is the code to make text bold

in order to make text bold
output:
in order to make text bold

here is the code to make text italic

in order to make text bold
output:
in order to make text Italic

here is the code to make text underline

in order to make text underline
output:
in order to make text underline

here is the code to make text super script

in order to make text Super Script
output:
in order to make text Super Script

here is the code to make text Sub script

in order to make text Sub Script
output:
in order to make text Super Script


how to use horizontal line tag in html

in this web programming tutorial we will learn that how we can use HR tag in an html document or in a web page using html.
 






how to use line break tag using html

In this web programming tutorial we will learn that how we can use Line Break tag in an html document tag.
Line breaks are used to decide where the text will break on a line or continue to the end of the window. it can be used to move the control to the next new line.
see the below code and example syntax of code of line break tag
this is line one<br>

this is line tow<br> 

this is line three<br> 


how to use paragraph tag in html

in this web programming tutorial we will learn that how we can use paragraph tag in an html document or in a web page.

paragraph tag are used in a document to add text in such a way that it will automatically adjust the end of line to suit the window size of the browser.

see the below example of paragraph tag

  

this is paragraph tag


how to use heading tag in html

in this web programming tutorial we will learn that how we can use heading tag heading in a html page.
headings are very important part of any web page. it is used to display different type of heading in HTML document
heading tag is a pair tag, pair tag means every opening tag must have a closing tag.
see the below code of heading tags. it has 6 types as follows

this is heading type 1

this is heading type 2

this is heading type 3

this is heading type 4

this is heading type 5
this is heading type 6
Output

this is heading type 1

this is heading type 2

this is heading type 3

this is heading type 4

this is heading type 5
this is heading type 6

Thursday, May 17, 2012

how to create basic html page

in this web programming tutorial we will learn that how we can create a basic html page. just copy and paste the below code in any editor such as note pad and save the file as test.html. just double click to run the page.

 
   my first page
 
 
     this is body of the page. web-healer.blogspot.com


Sunday, May 13, 2012

How to generate random numbers in asp.net using c#

in this we programming tutorial we will learn that how we can create random number in asp.net using c#. see the below code and just copy and paste.
Random rand = new Random((int)DateTime.Now.Ticks);
        int numIterations = 0;
        numIterations=  rand.Next(1, 100);
        Response.Write(numIterations.ToString());