programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Thursday, September 19, 2013

Use of File upload control in

How to use of File upload control in  : File-upload control in programming basically use for uploading file on server.when we need fouler save any type of files in web site of through web site then use this in programming ,for example when we want to save the profile pic ,or want to give the facility of online registration the we need upload photo and signature etc, 
the give the facility for file uploading and provide a simple controls .
In this Post we give some code of we make function to store(upload) image in server.

Code for File-upload control

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class fileupload : System.Web.UI.Page
    DataUtility du = new DataUtility();
    string filename,file;
    protected void Page_Load(object sender, EventArgs e)
    protected void Button1_Click(object sender, EventArgs e)
        string[] files = Directory.GetFiles("C:\\Users\\Quant\\Desktop\\grid");
        int numFiles = files.Length;
        int flname = numFiles + 1;
        string extention=System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
        if (FileUpload1.HasFile && flname <=10)
            if (extention == ".pdf" || extention == ".jpg")
                Label1.Text = "";
                filename = FileUpload1.PostedFile.FileName;
                file = Server.MapPath("./File/" + filename);
                string str = "insert into File_upload values('" + TextBox1.Text + "','" + file + "')";
                int i = du.ExecQry(str);
                Label1.Text = "Successfully Submitted";
                Label1.ForeColor = System.Drawing.Color.Green;
                Label1.Text = "Only pdf and jpg file uploaded";
                Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text="cant exceed ";
    } Controls And Examples with code: