public List<DocumentLibraryModel> GetDocumentModel(string folderPath, string libraryName,string user,string secret) { var docLib = new DocumentLibrary { FolderPath = folderPath.Replace(Common.Configuration.ApplicationConfiguration.FolderPath + "/", "/"). Equals(Common.Configuration.ApplicationConfiguration.RootFolderPath) ? Common.Configuration.ApplicationConfiguration.RootFolderPath : folderPath.Replace(Common.Configuration.ApplicationConfiguration.FolderPath + "/", "/"), LibraryName = libraryName }; var documentService = new MobilityDocumentsService(); var documentsResult = documentService.GetDocuments(docLib, user, secret); var documents = new List<DocumentLibraryModel>(); documents.AddRange(documentsResult.ToDocumentLibraryModels(folderPath)); return documents; }
public ActionResult CreateFolder(FormCollection collection) { var folderPath = (string)Session["UploadPath"]; var libraryName = (string)Session["LibraryName"]; var txtfolderName = collection.Get("txtfolderName"); var sortField = collection.Get("hdnsortField"); var sortDir = collection.Get("hdnsortDir"); try { var stringArray = new string[15] { @"\", "/", ":", "*", "?", "\"", "<", ">", "|", "#", "{", "}", "%", "~", "&" }; if (ContainAnyOf(txtfolderName.Trim(), stringArray)) throw new Exception("The folder name is invalid. A file name cannot contain any of the following characters: \\ / : * ? \" < > | # { } % ~ &"); if (!string.IsNullOrEmpty(txtfolderName.Trim())) { var document = new DocumentLibrary() { FolderName = new CultureInfo("en").TextInfo.ToTitleCase(txtfolderName.Trim().ToLower()), ParentFolder = libraryName, FolderPath = folderPath, Name = txtfolderName.Trim(), LibraryName = libraryName }; DocumentLibraryService.CreateFolder(document); } else throw new Exception("Please enter name for folder!"); ViewBag.LibraryName = libraryName; ViewBag.UploadPath = folderPath; ViewBag.SortField = sortField; ViewBag.SortDir = sortDir; return RedirectToAction("DocumentContainer", "Documents", new { LibraryName = libraryName, FolderPath = folderPath, SortField = sortField, SortDir = sortDir, Type = "DocLib" }); } catch (Exception ex) { throw ex; } }
public string UploadMultipleFiles() { var req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); var json = new StreamReader(req).ReadToEnd(); FileUpload input = null; bool response = true; input = JsonConvert.DeserializeObject<FileUpload>(json);//UploadPath var libraryName = string.IsNullOrEmpty(Convert.ToString(Session["LibraryName"])) ? input.LibraryName : Convert.ToString(Session["LibraryName"]); var folderPath = string.IsNullOrEmpty(Convert.ToString(Session["UploadPath"])) ? input.FolderPath : Convert.ToString(Session["UploadPath"]); var sortField = string.Empty; var sortDir = string.Empty; byte[] byd = Convert.FromBase64String(input.FileStream); var documentModel = new DocumentLibraryModel() { Name = Path.GetFileName(input.Name), ContentType = "plain/text", FolderPath = folderPath }; var document = new DocumentLibrary() { Name = new CultureInfo("en").TextInfo.ToTitleCase(documentModel.Name.ToLower()), FolderPath = folderPath, LibraryName = libraryName, Stream = new MemoryStream(byd) }; if (!string.IsNullOrEmpty(input.Name)) { response =DocumentLibraryService.UploadDocuments(document); } ViewBag.LibraryName = libraryName; ViewBag.UploadPath = folderPath; ViewBag.SortField = sortField; ViewBag.SortDir = sortDir; Session["UploadPath"] = folderPath; Session["LibraryName"] = libraryName; return input.Name + "|" + folderPath + "|" + libraryName + "|" + response; }
public ActionResult UploadFile(FormCollection collection) { var folderPath = (string)Session["UploadPath"]; var libraryName = (string)Session["LibraryName"]; var sortField = collection.Get("hdnsortField"); var sortDir = collection.Get("hdnsortDir"); try { var stringArray = new string[15] { @"\", "/", ":", "*", "?", "\"", "<", ">", "|", "#", "{", "}", "%", "~", "&" }; int numFiles = Request.Files.Count; for (int i = 0; i < numFiles; i++) { var uploadedFile = Request.Files[i]; var filename = Path.GetFileName(uploadedFile.FileName); if (filename.Split('.')[0].Length > 121) throw new Exception( "Please verify file name length, It must be less then equal to 120 char."); if (Request.Files.Count == 1 && filename == string.Empty) throw new Exception("Please select file to upload!"); if (Request.Files.Count == 1 && (ContainAnyOf(filename, stringArray) || uploadedFile.ContentLength <= 0)) throw new Exception( "The file name is invalid or the file is empty. A file name cannot contain any of the following characters: \\ / : * ? \" < > | # { } % ~ &"); var streamData = uploadedFile.InputStream; var documentModel = new DocumentLibraryModel() { Name = Path.GetFileName(uploadedFile.FileName), ContentType = "plain/text", FolderPath = folderPath }; var document = new DocumentLibrary() { Name = new CultureInfo("en").TextInfo.ToTitleCase(documentModel.Name.ToLower()), FolderPath = documentModel.FolderPath, LibraryName = libraryName, Stream = streamData }; if (!string.IsNullOrEmpty(filename)) DocumentLibraryService.UploadDocuments(document); } ViewBag.LibraryName = libraryName; ViewBag.UploadPath = folderPath; ViewBag.SortField = sortField; ViewBag.SortDir = sortDir; return RedirectToAction("DocumentContainer", "Documents", new { LibraryName = libraryName, FolderPath = folderPath, SortField = sortField, SortDir = sortDir, Type = "DocLib" }); } catch (Exception ex) { throw ex; } }
public ActionResult DownloadPdf(string documentName, string libraryName, string folderPath) { try { var localPath = AppDomain.CurrentDomain.BaseDirectory + ApplicationConfiguration.RemoveDirectoryNFileFromServer + "/"; if (!Directory.Exists(localPath)) Directory.CreateDirectory(localPath); var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName, LocalDirectoryPath = localPath }; DocumentLibraryService.GetDocuments(document); return File(document.LocalDirectoryPath + document.Name, document.ContentType, document.Name); } catch (Exception ex) { throw ex; } }
public ActionResult Download(string documentName, string libraryName, string folderPath) { var accountInfo = new AccountInfo(); var extArr = documentName.Split('.'); var docWithoutExt = documentName.ReplaceWithEmpty("." + extArr[extArr.Length - 1]); var dirPath = ApplicationConfiguration.RemoveDirectoryNFileFromServer.StartWithSlash() + "/"; var key = Guid.NewGuid(); var guidFileName = key + "." + extArr[extArr.Length - 1]; var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName, LocalDirectoryPath = dirPath, GuidDocumentName = guidFileName }; DocumentLibraryService.GetDocuments(document); var appKey = new ApplicationKey() { AppId = Guid.NewGuid(), Key = key, DocumentName = guidFileName, OriginalDocumentName = documentName, DocumentPath = dirPath, UserName = accountInfo.GetUserName(), CreatedDate = DateTime.Now, CreatedBy = accountInfo.GetUserName(), IsDeleted = false, LastUpdatedDate = DateTime.Now, LastUpdatedBy = accountInfo.GetUserName(), CurrentPage = 1, StatusId = (int)ProcessorStatus.UnProcessed }; ApplicationKeyService.InsertApplicationKey(appKey); appKey = ApplicationKeyService.GetApplicationKey(appKey); appKey.DocumentName = docWithoutExt; ViewBag.Folder = appKey.Key.ToString(); ViewBag.TotalPages = appKey.PageCount; ViewBag.DocumentName = appKey.DocumentName; return View("Viewer"); }
public ActionResult Delete(string name, string libraryName, string folderPath, string contentType, string sortField, string sortDir, string Type) { try { var document = new DocumentLibrary() { FolderPath = folderPath, Name = name, LibraryName = libraryName, ContentType = contentType }; DocumentLibraryService.DeleteDocuments(document); ViewBag.UploadPath = folderPath; ViewBag.LibraryName = libraryName; ViewBag.SortField = sortField; ViewBag.SortDir = sortDir; var output = GetDocumentModel(folderPath, libraryName, sortField, sortDir, Type); return PartialView("DocumentDetails", output); //return RedirectToAction("DocumentContainer", "Documents", new { LibraryName = libraryName, FolderPath = folderPath, SortField = sortField, SortDir = sortDir, Type = "DocLib" }); } catch (Exception ex) { throw ex; } }
public DocumentLibrary GetDocumentsInfo(DocumentLibrary documentLibrary) { return DocumentLibraryDao.GetDocumentsInfo(documentLibrary); }
public List<DocumentLibrary> GetAllDocumentsById(DocumentLibrary documentLibrary) { return DocumentLibraryDao.GetAllDocumentsById(documentLibrary); }
public DocumentLibrary GetPermission(DocumentLibrary documentLibrary) { return DocumentLibraryDao.GetPermission(documentLibrary); }
public bool DeleteDocuments(DocumentLibrary documentLibrary) { return DocumentLibraryDao.DeleteDocuments(documentLibrary); }
public bool CreateFolder(DocumentLibrary documentLibrary) { return DocumentLibraryDao.CreateFolder(documentLibrary); }
public bool UploadDocuments(DocumentLibrary documentLibrary) { return DocumentLibraryDao.UploadDocuments(documentLibrary); }
public string CheckOutFile(string fileCheckOut, string documentName, string libraryName, string folderPath) { string msg = string.Empty; try { var logedInUser = GetUserName().ToLower(); var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName }; document = DocumentLibraryService.GetDocumentsInfo(document); var docCheckOutUser = document.CheckedOutUserName.ToLower(); if (docCheckOutUser == string.Empty) { DocumentLibraryService.CheckOutFile(fileCheckOut); msg = "The file has been successfully checked out"; } else if (docCheckOutUser != logedInUser) msg = "This file has already been checked out by " + document.CheckedOutUserName; else if (docCheckOutUser == logedInUser) msg = "The file has already been checked out by you"; } catch (SoapException ex) { msg = "Error while checking out the file, please try again!"; //if (ex.Detail.InnerText.Contains("checked out for")) // msg = "This file has already been checked out by another user"; } return msg; }
private List<DocumentLibraryModel> GetDocumentModel(string folderPath, string libraryName, string sortField, string sortDir, string Type) { try { var account = new AccountInfo(); var docModel = new DocumentLibraryModel() { FolderPath = folderPath, LibraryName = libraryName, SortField = sortField, SortDir = sortDir }; var docLib = new DocumentLibrary() { FolderPath = docModel.FolderPath, LibraryName = docModel.LibraryName, SortField = docModel.SortField, SortDir = docModel.SortDir }; var logInUser = account.GetFullName(); var documents = DocumentLibraryService.GetAllDocuments(docLib); var output = new List<DocumentLibraryModel>(); foreach (var model in documents) { output.Add(new DocumentLibraryModel() { Name = model.Name, Description = model.Description, ContentType = model.ContentType, FolderPath = model.FolderPath, LibraryName = model.LibraryName, RelativePath = model.RelativePath, CreatedBy = model.CreatedBy, CreatedDate = model.CreatedDate, LastUpdated = model.LastUpdated, ModifieddBy = model.ModifieddBy, Permission = new SPPermissionModel() { CanAdd = model.Permission.CanAdd, CanDelete = model.Permission.CanDelete }, IsOldVersion = model.IsOldVersion, ImgSrc = model.ImgSrc, CheckedOutUserName = model.CheckedOutUserName, IsCheckedoutToLocal = model.IsCheckedoutToLocal, IsCheckedIn = CheckInStatus(model.CheckedOutUserName), IsCheckedOut = CheckOutStatus(model.CheckedOutUserName), LogInUserName = logInUser }); } var permission = DocumentLibraryService.GetPermission(docLib); ViewBag.canAdd = permission.Permission.CanAdd; return output; } catch (Exception ex) { throw ex; } }
public string CheckInFile(string fileCheckIn, string documentName, string libraryName, string folderPath, string comment, bool isCheckIn) { string msg = string.Empty; try { var logedInUser = GetUserName().ToLower(); var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName }; document = DocumentLibraryService.GetDocumentsInfo(document); var docCheckOutUser = document.CheckedOutUserName.ToLower(); if (docCheckOutUser == string.Empty) msg = "Check in will only work once you check out"; else if (docCheckOutUser != logedInUser) msg = "Check in will only work once you check out"; else if (docCheckOutUser == logedInUser && isCheckIn) { DocumentLibraryService.CheckInFile(fileCheckIn, comment); msg = "The file has been successfully checked in"; } } catch (SoapException ex) { msg = "Error while checking in the file, please try again!"; } return msg; }
public void CreateDocumentImage(string documentName, string user, string secret, string folderPath, out string docWithoutExt, out ApplicationKey appKey) { var libraryName = Common.Configuration.ApplicationConfiguration.LibraryName; var applicationKeyService = new ApplicationKeyService(); var extArr = documentName.Split('.'); docWithoutExt = documentName.ReplaceWithEmpty("." + extArr[extArr.Length - 1]); var dirPath = ApplicationConfiguration.RemoveDirectoryNFileFromServer.StartWithSlash() + "/"; var key = Guid.NewGuid(); var guidFileName = key + "." + extArr[extArr.Length - 1]; var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName, LocalDirectoryPath = dirPath, GuidDocumentName = guidFileName }; var mobilityDocumentsService = new MobilityDocumentsService(); mobilityDocumentsService.GetDocumentFromSharepointLibrary(document, user, secret, Common.Configuration.ApplicationConfiguration.DocStorePath); appKey = new ApplicationKey() { AppId = Guid.NewGuid(), Key = key, DocumentName = guidFileName, OriginalDocumentName = documentName, DocumentPath = dirPath, UserName = user, CreatedDate = DateTime.Now, CreatedBy = user, IsDeleted = false, LastUpdatedDate = DateTime.Now, LastUpdatedBy = user, CurrentPage = 1, StatusId = (int)ProcessorStatus.UnProcessed }; applicationKeyService.InsertApplicationKey(appKey); }