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

Thursday, September 19, 2013

Use of File upload control in asp.net

How to use of File upload control in asp.net  :



Asp.net File-upload control in asp.net 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 asp.net 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 asp.net give the facility for file uploading and provide a simple controls .
In this Post we give some code of Asp.net Programming.here 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)
    {
        du.openConn();
    }
    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);
                FileUpload1.PostedFile.SaveAs(file);
                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;
            }
            else
            {
                Label1.Text = "Only pdf and jpg file uploaded";
                Label1.ForeColor = System.Drawing.Color.Red;
            }
        }
        else{
            Label1.Text="cant exceed ";
        }
        }
    }


Asp.net Controls And Examples with code: