コード例 #1
0
        /// <summary>Uploads files to the learner's drop box.</summary>
        /// <param name="files">The files to upload.</param>
        /// <param name="existingFilesToKeep">Existing files to keep.</param>
        public void UploadFiles(AssignmentUpload[] files, int[] existingFilesToKeep)
        {
            SPUser currentUser = CurrentUser;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    spSite.CatchAccessDeniedException = false;
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetOrCreateAssignmentFolder(assignmentProperties);
                        assignmentFolder.ApplyPermission(currentUser, SPRoleType.Reader);

                        AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(currentUser);

                        if (learnerSubFolder == null)
                        {
                            learnerSubFolder = assignmentFolder.CreateLearnerAssignmentFolder(currentUser);
                        }
                        else
                        {
                            learnerSubFolder.ResetIsLatestFiles(existingFilesToKeep, currentUser.ID);
                        }

                        CheckExtensions(spSite, files);

                        using (new AllowUnsafeUpdates(spWeb))
                        {
                            SlkUser currentSlkUser = new SlkUser(currentUser);
                            foreach (AssignmentUpload upload in files)
                            {
                                learnerSubFolder.SaveFile(upload.Name, upload.Stream, currentSlkUser);
                            }
                        }

                        ApplySubmittedPermissions(spWeb);
                    }
                }
            });
        }
コード例 #2
0
        private AssignmentFile SaveFile(SPFile file)
        {
            AssignmentFile assignmentFile = null;
            using (SPSite destinationSite = new SPSite(assignmentProperties.SPSiteGuid))
            {
                destinationSite.CatchAccessDeniedException = false;
                using (SPWeb destinationWeb = destinationSite.OpenWeb(assignmentProperties.SPWebGuid))
                {
                    using (new AllowUnsafeUpdates(destinationWeb))
                    {
                        // Temporarily turn off property promotion. Possible cause for exceptions saving docs. I don't actually know
                        // if settings this will disable it as without an update it's not persisted and we don't want to persist the
                        // setting, just turn it off for this addition. It may even work asynchronously.
                        destinationWeb.ParserEnabled = false;
                        SPUser learner = CurrentUser;
                        DropBox dropBox = new DropBox(store, destinationWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);
                        AssignmentFolder learnerSubFolder = null;

                        if (assignmentFolder == null)
                        {
                            assignmentFolder = dropBox.CreateAssignmentFolder(assignmentProperties);
                        }

                        // ApplyAssignmentPermission creates the learner folder if required
                        ApplyAssignmentPermission(learner, SPRoleType.Contributor, SPRoleType.Reader, true);
                        learnerSubFolder = assignmentFolder.FindLearnerFolder(learner);

                        using (Stream stream = file.OpenBinaryStream())
                        {
                            assignmentFile = learnerSubFolder.SaveFile(file.Name, stream, new SlkUser(learner));
                        }
                    }
                }
            }

            return assignmentFile;
        }