blob upload with thumbnail c#

   protected void RadAsyncUpload2_FileUploaded1(object sender, FileUploadedEventArgs e)
    {
        string path = SaveCompanyPhoto(e.File).Result;
        string path1 = SaveCompanythumbPhoto(e.File).Result;
        var report = txtreport.Text;
        //documentsentity.BookAppointmentDocumentDetails_Report = txtreport.Text;
        if (Session["Att"] == null)
        {
            if (dtProductList.Columns.Count == 0)
            {
                dtProductList.Columns.Add("Image", typeof(string));
                dtProductList.Columns.Add("Thumb_Img", typeof(string));
                dtProductList.Columns.Add("Date", typeof(DateTime));
                dtProductList.Columns.Add("Report", typeof(string));
            }
        }
        else
        {
            dtProductList = Session["Att"] as DataTable;
        }
        dtProductList.Rows.Add(path, path1, DateTime.Now, report);
        Session["Att"] = dtProductList;

        radgrid2.DataSource = dtProductList;
        radgrid2.DataBind();

        ScriptManager.RegisterStartupScript(this, this.GetType(), "clearUpload", String.Format("$find('{0}').deleteAllFileInputs()", RadAsyncUpload1.ClientID), true);
    }

    public async Task<string> SaveCompanythumbPhoto(UploadedFile LeadImage)
    {
        ImageUpload bs = new ImageUpload();
        string fg = "";
        if (Session["tempimage"] != null)
        {
            fg = Session["tempimage"].ToString();

        }
        if (LeadImage != null)
        {
            string target = Server.MapPath("~/UploadedImages");
            if (!Directory.Exists(target))
            {
                Directory.CreateDirectory(target);
            }
            // RadAsyncUpload1.UploadedFiles[0].SaveAs(Path.Combine(target, RadAsyncUpload1.UploadedFiles[0].GetName()));
            using (Bitmap originalImage = new Bitmap(LeadImage.InputStream))
            {
                int width = 265;
                int height = 265;
                Bitmap thumbnail = new Bitmap(width, height);
                using (Graphics g = Graphics.FromImage((System.Drawing.Image)thumbnail))
                    g.DrawImage(originalImage, 0, 0, width, height);
                string thumbnailFileName = Path.Combine(target,
                    string.Format("{0}_bthumb{1}", LeadImage.GetNameWithoutExtension(), LeadImage.GetExtension()));
                thumbnail.Save(thumbnailFileName);

                var IMAGEURL = await bs.UploadImageAsync1(thumbnailFileName, LeadImage.GetExtension(), LeadImage.ContentType);
                fg = IMAGEURL;
                if ((System.IO.File.Exists(thumbnailFileName)))
                {
                    System.IO.File.Delete(thumbnailFileName);
                }
                Session["tempimage"] = fg;
            }

        }
        return fg;

    }
    public async Task<string> SaveCompanyPhoto(UploadedFile LeadImage)
    {
        ImageUpload bs = new ImageUpload();
        string fg = "";
        if (Session["LdImage"] != null)
        {
            fg = Session["LdImage"].ToString();

        }
        if (LeadImage != null)
        {
            var imageUrl = await bs.UploadImageAsync(LeadImage);
            Session["LdImage"] = imageUrl;
            fg = imageUrl;
            //Session.Timeout = 50;
        }
        return fg;
    }

Comments

Popular posts from this blog

Create Schema Using C# Asp .Net Dynamically.

How to post image in blob using Windows Azure.

Create your own captcha image generator in asp.net using c#.net