Пример #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.";
            }
        }
Пример #2
0
    protected void ImageButtonPhotoSave_Click(object sender, ImageClickEventArgs e)
    {
        DataTable     dt      = new DataTable();
        DataSet       ds      = new DataSet();
        SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShopConnectionString"].ConnectionString);
        SqlCommand    sqlCmd  = new SqlCommand("sp_photoAdd", sqlConn);

        sqlCmd.CommandType = CommandType.StoredProcedure;
        sqlCmd.Parameters.Add("@Type", SqlDbType.Int).Value      = 2;
        sqlCmd.Parameters.Add("@ItemId", SqlDbType.Int).Value    = Convert.ToInt32(Request.QueryString["CouponId"]);
        sqlCmd.Parameters.Add("@Text", SqlDbType.NVarChar).Value = TextBoxPhotoText.Text;

        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();

        SqlDataAdapter sda = new SqlDataAdapter("sp_photoIdGet", sqlConn);

        sda.SelectCommand.CommandType = CommandType.StoredProcedure;
        sda.SelectCommand.Parameters.Add("@Type", SqlDbType.Int).Value   = 2;
        sda.SelectCommand.Parameters.Add("@ItemId", SqlDbType.Int).Value = Convert.ToInt32(Request.QueryString["CouponId"]);
        sda.Fill(ds);
        dt = ds.Tables[0];

        //use WebManager to get the file, and save it
        IImageInfo img = WebManager.GetImageInfo(FileUploadPhotoNew);

        img.Path     = Server.MapPath("~") + "\\Files\\temp\\";
        img.FileName = dt.Rows[0]["PhotoId"].ToString() + ".jpg";

        //now create resized versions, and save them
        IImageInfo imgResize = img.ResizeMe(400, 267);          //constrain to 120 pixels wide

        imgResize.Save("~/Files/Photos/");                      //save file in a folder named "large"

        img.FileName = dt.Rows[0]["PhotoId"].ToString() + "t.jpg";
        IImageInfo imgTiny = img.ResizeMe(60, 40);          //constrain to 16 pixels high

        imgTiny.Save("~/Files/Photos/");

        //dt.Rows[0]["PhotoId"].ToString();

        sda.Dispose();
        sqlConn.Close();

        sqlCmd.Dispose();
        sqlConn.Dispose();

        LabelPhotoMessage.Visible  = true;
        LabelPhotoMessage.Text     = "تصویر اضافه گردید.";
        LabelPhotoMessage.CssClass = "SuccessMessage";

        GridViewPhotos.DataBind();
    }
Пример #3
0
        protected void photoUpload()
        {
            if (FileUpload1.HasFile)
            {
                string filePath = "~/Files/Temp/" + FileUpload1.FileName;
                if (Path.GetExtension(filePath).ToLower() == ".jpg" || Path.GetExtension(filePath).ToLower() == ".jpeg")
                {
                    string fileName     = Session["UserId"] + ".jpg";
                    string relativePath = @"~\Files\Temp\" + fileName;
                    FileUpload1.SaveAs(Server.MapPath(relativePath));

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

                    //now create resized versions, and save them
                    IImageInfo img220 = img.ResizeMe(100, 100);
                    img220.Save("~/Files/Temp/");

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

                    //try
                    //{
                    File.Move(Server.MapPath("~") + "\\Files\\Temp\\" + Session["UserId"] + "-100.jpg", Server.MapPath("~") + "\\Files\\ProfilesPhotos\\" + Session["UserId"] + "-100.jpg");
                    //}
                    //catch
                    //{
                    //}

                    HiddenFieldHasPhoto.Value = "true";
                }
            }
            else
            {
                if (HiddenFieldPhotoUrl.Value.Length > 1)
                {
                    //try
                    //{
                    File.Move(Server.MapPath("~") + "\\Files\\Temp\\" + Session["UserId"] + "-100.jpg", Server.MapPath("~") + "\\Files\\ProfilesPhotos\\" + Session["UserId"] + "-100.jpg");
                    //}
                    //catch
                    //{
                    //}

                    HiddenFieldHasPhoto.Value = "true";
                }
            }
        }