Showing posts with label image uploading. Show all posts
Showing posts with label image uploading. Show all posts

Nov 21, 2009

File upload examle

 protected void btnupload_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                try
                {
                  
                        if (FileUpload1.PostedFile.ContentLength < 102400)
                        {
                            string filename = Path.GetFileName(FileUpload1.FileName);
                            string s1 = filename;

                            string email = "v";
                            s1 = email + ".jpg";

                            string path = Server.MapPath("img/");
                            string fullPath = path + s1;
                            if (fullPath != "")
                            {

                                File.Delete(fullPath);
                            }

                            FileUpload1.SaveAs(fullPath);


                          
                            string p = "img/" + s1;
                         
                          

                            imgpic.ImageUrl = p;
                            imgpic.Visible = true;
                            imgpic.Height = 100;
                            imgpic.Width = 75;



                            lblres.Text = "Upload status: File uploaded!";
                        }
                        else
                            lblres.Text = "Upload status: The file has to be less than 100 kb!";
                   
                }
                catch (Exception ex)
                {
                    lblres.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }

            }
        }