Ejemplo n.º 1
0
        void FilePickerDialog1_UploadClicked(object sender, Academic.ViewModel.FileResourceEventArgs e)
        {
            //save file information to database
            var user = Page.User as CustomPrincipal;

            if (user != null)
            {
                using (var helper = new DbHelper.WorkingWithFiles())
                {
                    var fileName = Path.GetFileName(e.FilePath);
                    var fi       = new Academic.DbEntities.UserFile()
                    {
                        Id        = e.Id,
                        CreatedBy = user.Id
                        ,
                        CreatedDate = DateTime.Now
                        ,
                        DisplayName = e.FileDisplayName                           //Path.GetFileName(imageFile.FileName)
                        ,
                        FileDirectory = DbHelper.StaticValues.PrivateFiesLocation //CourseFilesLocation //StaticValue.UserImageDirectory
                        ,
                        FileName = fileName
                                   //Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                        ,
                        FileSizeInBytes = e.FileSizeInBytes //imageFile.ContentLength
                        ,
                        FileType = e.FileType               //imageFile.ContentType
                        ,
                        IconPath = e.IconPath
                        ,
                        IsFolder = false
                        ,
                        IsServerFile = IsServerFile
                        ,
                        SchoolId = user.SchoolId
                                   //SubjectId = SubjectId
                                   //,
                                   //Void = !f.Visible
                    };
                    var folderId = FolderId;
                    if (folderId > 0)
                    {
                        fi.FolderId = folderId;
                    }
                    var saved = helper.AddOrUpdateFile(fi);
                    if (saved != null)
                    {
                        //Response.Redirect("~/Views/Course/Section/Master/CourseSectionListing.aspx?SubId=" + SubjectId + "&edit=1#section_" + SectionId);
                        FilePickerDialog1.CloseDialog();
                        FileListingUc1.ResetView();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveFile(int userId, int schoolId, Academic.DbEntities.User.Users savedUser)
        {
            using (var helper = new DbHelper.User())
                using (var fileHelper = new DbHelper.WorkingWithFiles())
                {
                    //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile);

                    //if (savedUser != null)
                    //{
                    //public bool UploadToFolder(HttpPostedFileBase file)
                    //{
                    //    var filename = Path.GetFileName(file.FileName);
                    //    var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename);
                    //    file.SaveAs(path);
                    //    return true;
                    //}

                    //save image
                    //first entry to database : table File --its image
                    if (FileUpload1.HasFile)
                    {
                        var imageFile = FileUpload1.PostedFile;

                        var userPhotoFolder = fileHelper.GetUserPhotoFolder(schoolId);
                        if (userPhotoFolder != null)
                        {
                            var image = new Academic.DbEntities.UserFile()
                            {
                                CreatedBy = userId
                                ,
                                CreatedDate = DateTime.Now
                                ,
                                DisplayName = Path.GetFileName(imageFile.FileName)
                                ,
                                FileDirectory = DbHelper.StaticValues.UserImageDirectory
                                ,
                                FileName =
                                    Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                                ,
                                FileSizeInBytes = imageFile.ContentLength
                                ,
                                FileType = imageFile.ContentType
                                ,
                                IsServerFile = true
                                ,
                                SchoolId = schoolId
                                ,
                                FolderId = userPhotoFolder.Id
                            };
                            using (var fhelper = new DbHelper.WorkingWithFiles())
                            {
                                GetNewGuid(fhelper, image);
                                //TrimFirstLetterFromImageFileName(image);
                                if (trimLoop > 9 || guidLoop > 9)
                                {
                                    //cancel all save
                                }
                                else
                                {
                                    var savedFile = fhelper.AddOrUpdateFile(image);

                                    if (savedFile != null)
                                    {
                                        //save the image with this name
                                        //var filename = Path.GetFileName(file.FileName);
                                        var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory),
                                                                image.FileName);
                                        imageFile.SaveAs(path);

                                        //add the image Id to user
                                        helper.UpdateUsersImage(savedUser.Id, savedFile.Id);
                                    }
                                }
                            }
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "'User Photos' directory not found.";
                        }
                        if (savedUser != null)
                        {
                            ResetTextAndCombos();
                        }
                    }
                    //else
                    //    label.Text = "Error while saving.";
                    //}
                }
        }
Ejemplo n.º 3
0
        private void SaveFile(int userId, Academic.DbEntities.User.Users savedUser)
        {
            using (var helper = new DbHelper.User())
            {
                //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile);

                //if (savedUser != null)
                //{
                //public bool UploadToFolder(HttpPostedFileBase file)
                //{
                //    var filename = Path.GetFileName(file.FileName);
                //    var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename);
                //    file.SaveAs(path);
                //    return true;
                //}

                //save image
                //first entry to database : table File --its image
                if (FileUpload1.HasFile)
                {
                    var imageFile = FileUpload1.PostedFile;


                    var image = new Academic.DbEntities.UserFile()
                    {
                        CreatedBy = userId
                        ,
                        CreatedDate = DateTime.Now
                        ,
                        DisplayName = Path.GetFileName(imageFile.FileName)
                        ,
                        FileDirectory = DbHelper.StaticValues.UserImageDirectory
                        ,
                        FileName = Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                        ,
                        FileSizeInBytes = imageFile.ContentLength
                        ,
                        FileType = imageFile.ContentType
                        ,
                    };
                    using (var fhelper = new DbHelper.WorkingWithFiles())
                    {
                        GetNewGuid(fhelper, image);
                        //TrimFirstLetterFromImageFileName(image);
                        if (trimLoop > 9 || guidLoop > 9)
                        {
                            //cancel all save
                        }
                        else
                        {
                            var savedFile = fhelper.AddOrUpdateFile(image);

                            if (savedFile != null)
                            {
                                //save the image with this name
                                //var filename = Path.GetFileName(file.FileName);
                                var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory),
                                                        image.FileName);
                                imageFile.SaveAs(path);

                                //add the image Id to user
                                helper.UpdateUsersImage(savedUser.Id, savedFile.Id);


                                //    return true;
                            }
                        }
                    }
                }
                //}

                //Label label = (Label)this.Page.FindControl("lblBodyMessage");
                //if (label != null)
                //{
                if (savedUser != null)
                {
                    //label.Text = "Save Successful.";
                    //Page.Response.Redirect("List.aspx");

                    ResetTextAndCombos();
                }
                //else
                //    label.Text = "Error while saving.";
                //}
            }
        }