.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Upload/Download file in server

Posted By:Gowthammanju       Posted Date: June 28, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

This article explains you about processing of uploading and downloading the files to the server
 

Hi,

These article said to posses 

   1) A file uploader

                   Which is used for uploading files to server

   2)A grid view

                Whic is used to store the uploaded file to te user and to delete it.


step1: Place a uploader in design page and write a coding as


protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
           
            fname = FileUpload1.FileName;
            spath = @"~\ssg\" + FileUpload1.FileName;
            fpath = Server.MapPath("ssg");
            fpath = fpath + @"\" + FileUpload1.FileName;            
            desc = TextBox2.Text;
            if (System.IO.File.Exists(fpath))
            {
                Label1.Text = "File Name already exists!";
                return;
            }
            else
            {
                FileUpload1.SaveAs(fpath);
            }
            //Store details in the SQL Server table
            StoreDetails();
            TextBox2.Text = "";
//Refresh grid
            LoadGrid();
        }
        else
        {
            Label1.Text="Please select file!";
        }
    }
step 2: Now for loading grid and storing details write coding as

void LoadGrid()
    {
        sqlcon.Open();
        sqlcmd = new SqlCommand("select * from fileDet", sqlcon);
        da = new SqlDataAdapter(sqlcmd);
        dt.Clear();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        else
        {
            GridView1.DataBind();
        }
        sqlcon.Close();
    }
Main concept behind this is

During uploaded time i have store the server path in the SQL Server.

 I had bind server path in Grid View Hyper link (Navigate URL).

Then bind in grid view If user click the file name in the grid view then files are downloaded.

NOTE: Create the folder named ssg in your application


Please find attachment for more details...

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend