/// <summary> /// Removes characters from a string that can't exist in an URL. /// </summary> /// <param name="input">The string to remove illegal characters from</param> /// <returns></returns> public static string RemoveIllegalUrlCharacters(string input) { input = input.Trim(); int index = SPUrlUtility.IndexOfIllegalCharInUrlLeafName(input); while (index >= 0) { input = input.Remove(index, 1); index = SPUrlUtility.IndexOfIllegalCharInUrlLeafName(input); } return(input); }
private bool IsValidFile() { FileUpload uploadControl = (FileUpload)this.FindControl(UploadFileID); if (uploadControl.PostedFile == null || uploadControl.PostedFile.ContentLength <= 0) { ShowMessage(LoadResource("InvalidFile")); return(false); } if (SPUrlUtility.IndexOfIllegalCharInUrlLeafName(Path.GetFileName(uploadControl.FileName)) > -1) { ShowMessage(LoadResource("InvalidCharsInFile")); return(false); } if (FileMaximumLimitReached(uploadControl.PostedFile.ContentLength)) { ShowMessage(LoadResource("MaximumFileSizeReached")); return(false); } return(true); }