protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { lblErrors.Text = null; var destination = FormatFileDestination(txtDestination.Text.Trim()); SPFile fileMoved = null; //loop through our list of selected Files and move them to their new destination foreach (SPFile moveFile in listFiles) { try { if (!SPFileExtensions.Exists(moveFile, destination)) { fileMoved = MoveFile(moveFile.Web, moveFile, destination); Logger.Instance.Info("Moved file: " + fileMoved.Name + " from " + moveFile.Url + " to " + moveFile.Url); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br />The file (" + moveFile.Name + ") you are trying to move exists at the destination." + "<br />") : errorMessages.Append("The file (" + moveFile.Name + ") you are trying to move exists at the destination." + "<br />"); lblItems.Text = null; } else { Logger.Instance.Error("Error in Batch File Moving: User attempted to copy " + moveFile.Name + " to a location where the file already exists.", DiagnosticsCategories.eCaseWeb); } } catch (System.ArgumentException argEx) { Logger.Instance.Error("Error in Batch File Moving: " + moveFile.Name, argEx, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br />The file you are trying to move, does not exist." + "<br />") : errorMessages.Append("The file you are trying to move, does not exist." + "<br />"); lblItems.Text = null; continue; } catch (System.IO.FileNotFoundException fnfEx) { Logger.Instance.Error("Error in Batch File Moving: " + moveFile.Name, fnfEx, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("The file you are trying to move could not be found. <br />") : errorMessages.Append("The file you are trying to move could not be found. + <br />"); lblItems.Text = null; continue; } catch (Exception ex) { Logger.Instance.Error("Error in Batch File Moving: " + moveFile.Name, ex, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder(ex.Message + "<br />") : errorMessages.Append(ex.Message + "<br />"); lblItems.Text = null; continue; } } //show any error messages that we have lblErrors.Text = errorMessages == null ? null : errorMessages.ToString(); if (errorMessages == null || errorMessages.Length == 0) { //close the modal Response.Write(string.Format(CultureInfo.InvariantCulture, "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, '{0}');</script>", listFiles.Count)); Response.Flush(); Response.End(); } } }
protected void btnSave_Click(object sender, EventArgs e) { string action = string.Empty; string actionDesc = string.Empty; LinkButton button = sender as LinkButton; if (button.ID == "btnCopy") { action = "copy"; actionDesc = "copied"; } else if (button.ID == "btnMove") { action = "move"; actionDesc = "moved"; } var destination = FormatFileDestination(txtDestination.Text.Trim()); SPFile fileProcessed = null; SPLongOperation longOp = new SPLongOperation(this.Page); longOp.LeadingHTML = "Please wait while your file(s) are being " + actionDesc + "..."; longOp.Begin(); var fileList = GetSelectedFiles(); foreach (SPFile file in fileList) { try { if (!SPFileExtensions.Exists(file, destination)) { fileProcessed = action == "copy" ? CopyFile(file, destination) : MoveFile(file, destination); Logger.Instance.Info("Processed file " + action + " for: " + fileProcessed.Name + " from " + file.Url + " to " + fileProcessed.Url); } else { Logger.Instance.Error("Error in Batch File Copy/Move: User attempted to copy " + file.Name + " to a location where the file already exists.", DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br /> " + file.Name + " already exists. <br />") : errorMessages.Append(file.Name + " already exists. <br />"); lblItems.Text = null; continue; } } catch (System.ArgumentException argEx) { Logger.Instance.Error("Error in Batch File Copying: " + file.Name, argEx, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br />The file you are trying to copy does not exist. <br />") : errorMessages.Append("The file you are trying to copy does not exist. <br />"); lblItems.Text = null; continue; } catch (System.IO.FileNotFoundException fnfEx) { Logger.Instance.Error("Error in Batch File Copying: " + file.Name, fnfEx, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br />The file you are trying to copy could not be found. <br />") : errorMessages.Append("The file you are trying to copy could not be found. <br />"); lblItems.Text = null; continue; } catch (Exception ex) { Logger.Instance.Error("Error in Batch File Copying: " + file.Name, ex, DiagnosticsCategories.eCaseWeb); errorMessages = errorMessages == null ? errorMessages = new StringBuilder("Error(s):<br />This URL contains invalid characters. <br />") : errorMessages.Append("This URL contains invalid characters. <br />"); lblItems.Text = null; continue; } } //show any error messages that we have lblErrors.Text = errorMessages == null ? null : errorMessages.ToString(); if ((errorMessages == null || errorMessages.Length == 0)) { //close the modal // Response.Write(string.Format(CultureInfo.InvariantCulture, "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, '{0}');</script>", treeViewSelectedDocs.Nodes.Count)); // Response.Flush(); // Response.End(); string strScript = "try { alert('File(s) " + actionDesc + " successfully.'); window.frameElement.commitPopup(); } catch (e) {}"; if (SPContext.Current.IsPopUI) { longOp.EndScript(strScript); } } else { errorMessages.Append("<br/><br/>Please <a href='#' onclick='history.go(-1);return false;'>go back</a> and try again."); longOp.EndScript("document.getElementById('s4-simple-card-content').innerHTML = \"<br/><br/><br/><h4>Errors have occurred during the submission.</h4>" + errorMessages.ToString() + " \";"); } }