示例#1
0
        protected void uploadButton_Click(object sender, EventArgs e)
        {
            var divtimespan = Master.FindControl("divtimespan") as HtmlGenericControl;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            //get input data
            DateTime now = DateTime.Now;
            string title = tbTitle.Text;
            string fileName = FileUpload1.FileName;
            string ext = Path.GetExtension(fileName);
            byte[] file = FileUpload1.FileBytes;
            using (var input = new MemoryStream(file))
            {
                //watermarking image
                var output = new MemoryStream();
                AddWaterMark(input, now.ToString(), output);
                file = new byte[output.Length];
                output.Position = 0;
                BinaryReader br = new BinaryReader(output);
                file = br.ReadBytes((int)output.Length);
                br.Close();
            }

            //save image to disk and database
            string path = Server.MapPath("Images");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            fileName = Guid.NewGuid().GetHashCode().ToString("x") + ext;
            path = path + "\\" + fileName;
            try
            {
                var ge = new GalleryEntities();
                Photos photo = new Photos();
                photo.fileName = fileName;
                photo.postingDate = DateTime.Now;
                photo.title = title;
                using (var fs = new FileStream(path, FileMode.Create))
                {
                    BinaryWriter bw = new BinaryWriter(fs);
                    bw.Write(file);
                }
                ge.AddToPhotos(photo);
                ge.SaveChanges();
            }
            finally { }
            ListView_Photos.DataBind();
            sw.Stop();
            if (divtimespan != null)
                divtimespan.InnerText = string.Format("Elapsed time: {0}", sw.Elapsed);
        }
示例#2
0
 /// <summary>
 /// Create a new Photos object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="postingDate">Initial value of the postingDate property.</param>
 /// <param name="title">Initial value of the title property.</param>
 /// <param name="fileName">Initial value of the fileName property.</param>
 public static Photos CreatePhotos(global::System.Int32 id, global::System.DateTime postingDate, global::System.String title, global::System.String fileName)
 {
     Photos photos = new Photos();
     photos.id = id;
     photos.postingDate = postingDate;
     photos.title = title;
     photos.fileName = fileName;
     return photos;
 }
示例#3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Photos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotos(Photos photos)
 {
     base.AddObject("Photos", photos);
 }
示例#4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Photos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotos(Photos photos)
 {
     base.AddObject("Photos", photos);
 }