private string ImageUpload()
        {
            List <ImageUrl> OthrContntPicTempFileUrlList = new List <ImageUrl>();
            ImageUrl        imageUrl = new ImageUrl();

            try
            {
                if (FileUploadImage.HasFile)
                {
                    string now = "";
                    now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture);
                    //take only letter or digit
                    var sb = new StringBuilder();
                    foreach (char t in now.Where(char.IsLetterOrDigit))
                    {
                        sb.Append(t);
                    }
                    now = sb.ToString();//save to now string
                    var    rnd = new Random(100000);
                    var    tempMatImageName = now + rnd.Next();
                    string path             = Server.MapPath("~/Image/OtherContentImage/");
                    FileUploadHelper.BindImage(FileUploadImage, path, tempMatImageName, 800, 800);
                    imageUrl.ImageUrlTemp = "~/Image/OtherContentImage/" + tempMatImageName + Path.GetExtension(FileUploadImage.FileName);

                    return(imageUrl.ImageUrlTemp.ToString());
                }
                return(imageUrl.ImageUrlTemp.ToString());
            }
            catch (Exception ex)
            {
                labelMessageOtherContent.Text = "error: " + ex.Message;
            }
            return(imageUrl.ImageUrlTemp.ToString());
        }
示例#2
0
        protected void btnMatPicUpload_Click(object sender, EventArgs e)
        {
            try
            {
                if (Session["seMatPicTempFileName"] == null)
                {
                    Session["seMatPicTempFileName"] = new List <ControlAdmin.MaterialWF.ImageUrl>();
                }

                List <ControlAdmin.MaterialWF.ImageUrl> matPicTempFileUrlList = new List <ControlAdmin.MaterialWF.ImageUrl>();
                using (PictureRT aPictureRt = new PictureRT())
                {
                    List <Picture> picList = new List <Picture>();
                    picList = aPictureRt.GetPictureByMaterialIID(Convert.ToInt64(Session["adGiverMatIID"]));

                    if (picList.Count > 0)
                    {
                        foreach (var picture in picList)
                        {
                            ControlAdmin.MaterialWF.ImageUrl aImageUrl = new ControlAdmin.MaterialWF.ImageUrl();
                            aImageUrl.ImageUrlTemp = picture.UrlAddress;
                            matPicTempFileUrlList.Add(aImageUrl);
                        }
                    }
                }


                if (MatPicUpload.HasFile)
                {
                    foreach (var file in MatPicUpload.PostedFiles)
                    {
                        string now = "";
                        now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture);

                        //take only letter or digit
                        var sb = new StringBuilder();
                        foreach (char t in now.Where(char.IsLetterOrDigit))
                        {
                            sb.Append(t);
                        }

                        now = sb.ToString();//save to now string
                        var rnd = new Random(100000);
                        var tempMatImageName = now + rnd.Next();

                        matPicTempFileUrlList = (List <ControlAdmin.MaterialWF.ImageUrl>)Session["seMatPicTempFileName"];//read from sess

                        string path = Server.MapPath("~/Image/MatTempImage/");
                        FileUploadHelper.BindImage(file, path, tempMatImageName);


                        ControlAdmin.MaterialWF.ImageUrl imageUrl = new ControlAdmin.MaterialWF.ImageUrl();
                        imageUrl.ImageUrlTemp = "~/Image/MatTempImage/" + tempMatImageName + Path.GetExtension(file.FileName);
                        matPicTempFileUrlList.Add(imageUrl);
                        Session["seMatPicTempFileName"] = matPicTempFileUrlList;//write to sess


                        labelMessage.Text = "File uploaded!";
                    }
                    datalistMatPic.DataSource = matPicTempFileUrlList;
                    datalistMatPic.DataBind();
                    btnDeleteImageTemp.Visible = true;
                }
                else
                {
                    labelMessage.Text      = "Please browse image(s)....";
                    labelMessage.ForeColor = System.Drawing.Color.Yellow;
                    labelMessage.Focus();
                }
            }
            catch (Exception ex)
            {
                labelMessage.Text = "error: " + ex.Message;
            }
        }
示例#3
0
        protected void btnMatPicUpload_Click(object sender, EventArgs e)
        {
            string debugStr = string.Empty;

            try
            {
                if (MatPicUpload.HasFile)
                {
                    List <ImageUrl> matPicTempFileUrlList = new List <ImageUrl>();
                    foreach (var file in MatPicUpload.PostedFiles)
                    {
                        string now = "";
                        now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff", CultureInfo.InvariantCulture);

                        //take only letter or digit
                        var sb = new StringBuilder();
                        foreach (char t in now.Where(char.IsLetterOrDigit))
                        {
                            sb.Append(t);
                        }

                        now = sb.ToString();//save to now string
                        var rnd = new Random(100000);
                        var tempMatImageName = now + rnd.Next();

                        if (Session["seMatPicTempFileName"] == null)
                        {
                            Session["seMatPicTempFileName"] = new List <ImageUrl>();
                        }
                        matPicTempFileUrlList = (List <ImageUrl>)Session["seMatPicTempFileName"];//read from sess
                        string path = Server.MapPath("~/Image/MatTempImage/");

                        debugStr += "FileName :" + tempMatImageName + "PsotFile :" + file.ToString() + "Server Path :" + path;

                        FileUploadHelper.BindImage(file, path, tempMatImageName);
                        ImageUrl imageUrl = new ImageUrl();
                        imageUrl.ImageUrlTemp = "~/Image/MatTempImage/" + tempMatImageName + Path.GetExtension(file.FileName);
                        matPicTempFileUrlList.Add(imageUrl);
                        Session["seMatPicTempFileName"] = matPicTempFileUrlList;//write to sess


                        labelMessage.Text      = "File uploaded!";
                        labelMessage.ForeColor = System.Drawing.Color.Green;
                    }
                    datalistTempMatImage.DataSource = matPicTempFileUrlList;
                    datalistTempMatImage.DataBind();

                    if (Session["seMatPicTempFileName"] != null)
                    {
                        btnDeleteImageTemp.Visible = true;
                    }
                }
                else
                {
                    labelMessage.Text      = "Please browse image(s)....";
                    labelMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                labelMessage.Text = "Error: " + ex.Message + "Stack Info " + ex.StackTrace + "Debug Info :" + debugStr;
                if (ex.InnerException != null)
                {
                    labelMessage.Text = "Error: " + ex.Message + "Inner Message :" + ex.InnerException.Message + " Stack Info " + ex.StackTrace + "Debug Info :" + debugStr;
                }
            }
        }