Ejemplo n.º 1
0
        protected void ButtonPhoto_Click(object sender, EventArgs e)
        {
            if (FileUploadPicture.HasFile)
            {
                string filePath = "~/Files/Temp/" + FileUploadPicture.FileName;
                if (Path.GetExtension(filePath).ToLower() == ".jpg" || Path.GetExtension(filePath).ToLower() == ".jpeg")
                {
                    string fileName     = Session["UserId"] + Path.GetExtension(filePath).ToLower();
                    string relativePath = @"~\Files\Temp\" + fileName;
                    FileUploadPicture.SaveAs(Server.MapPath(relativePath));

                    //use WebManager to get the file, and save it
                    IImageInfo img = WebManager.GetImageInfo(FileUploadPicture);
                    img.Path     = Server.MapPath("~") + "\\Files\\Temp\\";
                    img.FileName = Session["UserId"] + ".jpg";

                    //now create resized versions, and save them
                    IImageInfo img160 = img.ResizeMe(160, 160);
                    img160.Save("~/Files/" + ConfigurationManager.AppSettings["folderName"].ToString() + "/ProfilesPhotos/");

                    LabelPhotoMessage.Visible = true;
                    LabelPhotoMessage.Text    = "You have successfully uploaded your picture.";

                    HiddenFieldPhotoUrl.Value = "Files/" + ConfigurationManager.AppSettings["folderName"].ToString() + "/ProfilesPhotos/" + Session["UserId"].ToString() + ".jpg";

                    File.Delete(Server.MapPath("~") + "\\Files\\Temp\\" + fileName);

                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                    SqlCommand    sqlCmd  = new SqlCommand("sp_settingsPhotoEdit", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value   = Convert.ToInt32(Session["UserId"]);
                    sqlCmd.Parameters.Add("@HasPhoto", SqlDbType.Bit).Value = true;

                    try
                    {
                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        sqlConn.Close();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }
                }
                else
                {
                    LabelPhotoMessage.Visible = true;
                    LabelPhotoMessage.Text    = "Select a picture with JPG extenstion.";
                }
            }
            else
            {
                LabelPhotoMessage.Visible = true;
                LabelPhotoMessage.Text    = "Select a picture file.";
            }
        }
Ejemplo n.º 2
0
        protected void UploadPicture()
        {
            // Specify the path
            String savePath = Server.MapPath("~/Pictures/");

            // Verify that the FileUpload control contains a file.
            if (FileUploadPicture.HasFile)
            {
                // Get the name of the file to upload.
                String fileName = FileUploadPicture.FileName;

                // Get the extension of the uploaded file.
                string extension = System.IO.Path.GetExtension(fileName);

                if ((extension == ".jpg") || (extension == ".png"))
                {
                    // Add the path to the name of the file to upload
                    savePath += fileName;

                    // Call the SaveAs method to save the uploaded file to the path.
                    FileUploadPicture.SaveAs(savePath);

                    LabelMessageProduct.Text = "The file was saved as " + fileName;
                }
                else
                {
                    LabelMessageProduct.Text = "The file was not uploaded because it does not have a .jpg or .png extension.";
                }
            }
            else
            {
                // Notify the user that a file was not uploaded.
                LabelMessageProduct.Text = "Please specify a file to upload.";
            }
        }
Ejemplo n.º 3
0
    private void UpLoadAndDisplay()
    {
        string imgName = FileUploadPicture.FileName;
        string imgPath = imgName;
        int    imgSize = FileUploadPicture.PostedFile.ContentLength;

        if (FileUploadPicture.HasFile)
        {
            FileUploadPicture.SaveAs(Server.MapPath("~/Uploaded/" + imgPath));
            imgPic.ImageUrl = "~/Uploaded/" + imgPath;
            string pic = "~/Uploaded/" + imgPath;
            Session["pic"] = pic;
        }
    }
Ejemplo n.º 4
0
    protected void ButtonSendTheData_Click(object sender, EventArgs e)
    {
        FileInfo file = new FileInfo(Server.MapPath("~/Media/" + Path.GetFileName(FileUploadPicture.FileName)));

        if (file.Exists)
        {
            int ct = 1;
            while (true)
            {
                FileInfo file1 = new FileInfo(Server.MapPath("~/Media/(" + ct + ")" + Path.GetFileName(FileUploadPicture.FileName)));
                if (file1.Exists)
                {
                    ct++;
                }
                else
                {
                    FileUploadPicture.SaveAs(Server.MapPath("~/Media/(" + ct + ")" + Path.GetFileName(FileUploadPicture.FileName)));
                    break;
                }
            }

            //Insert in the DB
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MeetMeConnectionString"].ConnectionString);
            conn.Open();
            string     imageDB = "insert into Media(imgName, userId) values (@picName, @uID)";
            SqlCommand com     = new SqlCommand(imageDB, conn);
            com.Parameters.AddWithValue("@picName", "(" + ct + ")" + Path.GetFileName(FileUploadPicture.FileName).ToString());
            com.Parameters.AddWithValue("@uID", USERID);
            com.ExecuteNonQuery();
            conn.Close();
        }
        else
        {
            FileUploadPicture.SaveAs(Server.MapPath("~/Media/" + Path.GetFileName(FileUploadPicture.FileName)));

            //Insert in the DB
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MeetMeConnectionString"].ConnectionString);
            conn.Open();
            string     imageDB = "insert into Media(imgName, userId) values (@picName, @uID)";
            SqlCommand com     = new SqlCommand(imageDB, conn);
            com.Parameters.AddWithValue("@picName", Path.GetFileName(FileUploadPicture.FileName).ToString());
            com.Parameters.AddWithValue("@uID", USERID);
            com.ExecuteNonQuery();
            conn.Close();
        }

        //Reloading the page
        Response.Redirect("UserGallery.aspx");
    }