예제 #1
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            HttpPostedFile postedFile = this.filUpload.PostedFile;

            if (postedFile.ContentLength > 0)
            {
                _photo.Title     = txtTitle.Text;
                _photo.FileName  = PhotoService.CreateServerFilename(postedFile.FileName);
                _photo.Size      = postedFile.ContentLength;
                _photo.CreatedBy = (User)this.User.Identity;
                _photo.Section   = base.Section;
                _photo.Album     = _albumService.GetAlbumById(_albumId);

                // Save the file
                try
                {
                    _photoService.SavePhoto(_photo, postedFile.InputStream);

                    if (_photoId <= 0 && this._photo.Id > 0)
                    {
                        // This appears to be a new file. Store the id of the file in the viewstate
                        // so the file can be deleted if the user decides to cancel.
                        ViewState["tempPhotoId"] = _photo.Id;
                    }
                    BindPhoto();
                }
                catch (Exception ex)
                {
                    // Something went wrong
                    ShowError("Error saving the file: " + ex.Message);
                }
            }
        }
        private void btnMassImport_Click(object sender, EventArgs e)
        {
            if (_album == null)
            {
                ShowError("You have to create an album first");
                return;
            }

            try
            {
                DirectoryInfo directoryInfo = _album.GetDirectoryMassImport();

                foreach (FileInfo file in directoryInfo.GetFiles())
                {
                    if (checkFileType(file.Extension))
                    {
                        if (_album == null)
                        {
                            SaveAlbum();
                        }

                        Photo photo = new Photo();
                        photo.Title     = file.Name;
                        photo.FileName  = PhotoService.CreateServerFilename(file.Name);
                        photo.Size      = (int)file.Length;
                        photo.CreatedBy = (User)User.Identity;
                        photo.Section   = Section;
                        photo.Album     = _album;

                        MemoryStream stream = new MemoryStream(File.ReadAllBytes(file.FullName), true);

                        _photoService.SavePhoto(photo, stream);
                        file.Delete();
                    }
                }
                divFastImport.Visible = false;
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }