protected void _btnNewDocFolder_Click(object sender, EventArgs e) { try { if (_txtFolderName.Text.Trim() != string.Empty) { WSDocManagement.DocSvc docSvc = new WSDocManagement.DocSvc(); bool FolderAlreadyExists = false; foreach (DataRow _Dr in docSvc.GetFoldersByMatter(Session[SessionName.ProjectId].ToString().Trim()).Tables[0].Rows) { if (_Dr["DocAttributeValue"].ToString().Trim().ToLower() == _txtFolderName.Text.Trim().ToLower()) { FolderAlreadyExists = true; break; } } if (!FolderAlreadyExists) { // Save PlaceHolder (Folder) docSvc.SaveToDocTable(0, 1, "Placeholder_Folder.msf", 1, "PLACEHOLDER_FOLDER", string.Empty, null, false, DateTime.Now, DateTime.Now, false, false, false); int NewFolderDocId = docSvc.GetNewestFolderDocId(); // Save Doc Attributes docSvc.SaveToDocAttributes(NewFolderDocId, "1", 5); docSvc.SaveToDocAttributes(NewFolderDocId, _txtFolderName.Text.Trim(), 20); // Save Project Map Docs docSvc.InsertProjectMapDocs(NewFolderDocId, Session[SessionName.ProjectId].ToString().Trim()); _txtFolderName.Text = string.Empty; _lblError.Text = "Folder has been successfully created."; if (FolderAdded != null) { OnFolderAdded(e); } } else { _lblError.Text = "This matter already contains a folder with this name."; } } else { _lblError.Text = "Please enter a valid folder name."; } } catch (Exception ex) { _lblError.Text = ex.Message; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _btnSave_Click(object sender, EventArgs e) { DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { if (Session[SessionName.DocumentId] != null) { if (Convert.ToInt32(Session[SessionName.DocumentId]) > 0) { _editMode = true; } } string fileName = string.Empty; if (_editMode == false) { #region Upload File to Application Server if (_fileName.PostedFile != null) { if (!string.IsNullOrEmpty(_fileName.PostedFile.FileName)) { if (!CheckFileTypeExtension()) { _lblError.Text = UploadFileTypesErrorMessage; return; } if (!Directory.Exists(Path.Combine(Server.MapPath("."), "Upload"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("."), "Upload")); } _fileName.PostedFile.SaveAs(Server.MapPath(".") + "/Upload/" + _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1)); fileName = Server.MapPath(".") + "/Upload/" + _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1); } else { _lblError.Text = "Please select document."; return; } } #endregion } #region Load Details DocumentSearchItem docDetails = new DocumentSearchItem(); DocumentReturnValue docReturnValue = null; StartDocumentUploadReturnValue Header; docDetails.ProjectId = (Guid)Session[SessionName.ProjectId]; // Document Type is General docDetails.TypeId = 1; docDetails.FileDescription = _txtDocument.Text; docDetails.Notes = _txtNotes.Text; if (!string.IsNullOrEmpty(_ddlFeeEarner.SelectedValue)) { docDetails.FeeEarnerId = new Guid(GetValueOnIndexFromArray(_ddlFeeEarner.SelectedValue, 1)); } else { docDetails.FeeEarnerId = DataConstants.DummyGuid; } docDetails.IsPublic = _chkPublic.Checked; docDetails.UseVersioning = _chkUseVersioning.Checked; docDetails.IsEncrypted = _chkEncryptFile.Checked; docDetails.IsLocked = _chkLockDocument.Checked; #endregion if (_editMode == false) { if (string.IsNullOrEmpty(fileName)) { _lblError.Text = "Please select document."; return; } docDetails.FileName = fileName; docDetails.CreatedDate = DateTime.Today; docDetails.Id = 0; FileInfo FInfo = new FileInfo(fileName); // Create a hash of the file byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(fileName); #region Start Upload try { Header = _documentServiceClient.StartNewDocumentUploadForMatter(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, // Strip off the path as this is irrelavent FInfo.LastWriteTime, FInfo.Length, LocalHash, docDetails); } catch (Exception ex) { throw ex; } if (Header != null) { if (!Header.Success) { _lblError.CssClass = "errorMessage"; _lblError.Text = Header.Message; return; } } #endregion #region Upload Chunk by Chunk long BytesLeft = FInfo.Length; // Open the file using (FileStream FileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { while (BytesLeft > 0) { byte[] Bytes = new byte[Header.MaxChunkSize]; long Position = FileStream.Position; // Read at most MaxChunkSize bytes int ChunkSize = FileStream.Read(Bytes, 0, (int)Math.Min(BytesLeft, Header.MaxChunkSize)); // Upload the chunk ReturnValue Result = _documentServiceClient.DocumentUploadChunk( ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId, Position, ChunkSize, Bytes); if (!Result.Success) { throw new Exception("File upload failed: " + Result.Message); } BytesLeft -= ChunkSize; } } #endregion #region Upload Complete // Tell the service we have finished the upload docReturnValue = _documentServiceClient.DocumentUploadComplete(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId); #endregion if (File.Exists(fileName)) { File.Delete(fileName); } } else { docDetails.Id = Convert.ToInt32(Session[SessionName.DocumentId]); if (_ccCreatedDate.DateText.Length > 0) { docDetails.CreatedDate = Convert.ToDateTime(_ccCreatedDate.DateText); } try { docReturnValue = _documentServiceClient.EditMatterDocumentDetails(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, docDetails); } catch (Exception ex) { _lblError.Text = ex.Message; } } if (docReturnValue != null) { if (docReturnValue.Success) { if (docReturnValue.Document != null) { if (_editMode == false) { Session[SessionName.DocumentId] = docReturnValue.Document.Id; _editMode = true; } DisplayDocumentDetails(); _lblError.Text = "Document information saved successfully."; _lblError.CssClass = "successMessage"; if (_DdlFolder.SelectedItem.Text.Trim() != "General") { //docDetails.IsFolder = true; WSDocManagement.DocSvc _docSvc = new WSDocManagement.DocSvc(); if (_editMode) { _docSvc.SaveToDocAttributes(docDetails.Id, _DdlFolder.SelectedItem.Text, 20); } else { _docSvc.SaveToDocAttributes(_docSvc.GetNewestDocId(), _DdlFolder.SelectedItem.Text, 20); } } } } else { _lblError.Text = "Document information not saved.<br />" + docReturnValue.Message; _lblError.CssClass = "errorMessage"; } } } catch (Exception ex) { _lblError.Text = ex.Message; } finally { if (_documentServiceClient != null) { _documentServiceClient.Close(); } if (Session[SessionName.DocumentId] != null) { Session[SessionName.DocumentId] = null; } if (ItemChanged != null) { OnItemChanged(e); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _btnSave_Click(object sender, EventArgs e) { DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { if (Session[SessionName.DocumentId] != null) { if (Convert.ToInt32(Session[SessionName.DocumentId]) > 0) { _editMode = true; } } string fileName = string.Empty; if (_editMode == false) { #region Upload File to Application Server if (_fileName.PostedFile != null) { if (!string.IsNullOrEmpty(_fileName.PostedFile.FileName)) { if (!CheckFileTypeExtension()) { _lblError.Text = UploadFileTypesErrorMessage; return; } if (!Directory.Exists(Path.Combine(Server.MapPath("."), "Upload"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("."), "Upload")); } _fileName.PostedFile.SaveAs(Server.MapPath(".") + "/Upload/" + _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1)); fileName = Server.MapPath(".") + "/Upload/" + _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1); } else { _lblError.Text = "Please select document."; return; } } #endregion } #region Load Details DocumentSearchItem docDetails = new DocumentSearchItem(); DocumentReturnValue docReturnValue = null; StartDocumentUploadReturnValue Header; docDetails.ProjectId = (Guid)Session[SessionName.ProjectId]; // Document Type is General docDetails.TypeId = 1; docDetails.FileDescription = _txtDocument.Text; docDetails.Notes = _txtNotes.Text; if (!string.IsNullOrEmpty(_ddlFeeEarner.SelectedValue)) { docDetails.FeeEarnerId = new Guid(GetValueOnIndexFromArray(_ddlFeeEarner.SelectedValue, 1)); } else { docDetails.FeeEarnerId = DataConstants.DummyGuid; } docDetails.IsPublic = _chkPublic.Checked; docDetails.UseVersioning = _chkUseVersioning.Checked; docDetails.IsEncrypted = _chkEncryptFile.Checked; docDetails.IsLocked = _chkLockDocument.Checked; #endregion if (_editMode == false) { if (string.IsNullOrEmpty(fileName)) { _lblError.Text = "Please select document."; return; } docDetails.FileName = fileName; docDetails.CreatedDate = DateTime.Today; docDetails.Id = 0; FileInfo FInfo = new FileInfo(fileName); // Create a hash of the file byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(fileName); #region Start Upload try { Header = _documentServiceClient.StartNewDocumentUploadForMatter(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, // Strip off the path as this is irrelavent FInfo.LastWriteTime, FInfo.Length, LocalHash, docDetails); } catch (Exception ex) { throw ex; } if (Header != null) { if (!Header.Success) { _lblError.CssClass = "errorMessage"; _lblError.Text = Header.Message; return; } } #endregion #region Upload Chunk by Chunk long BytesLeft = FInfo.Length; // Open the file using (FileStream FileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { while (BytesLeft > 0) { byte[] Bytes = new byte[Header.MaxChunkSize]; long Position = FileStream.Position; // Read at most MaxChunkSize bytes int ChunkSize = FileStream.Read(Bytes, 0, (int)Math.Min(BytesLeft, Header.MaxChunkSize)); // Upload the chunk ReturnValue Result = _documentServiceClient.DocumentUploadChunk( ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId, Position, ChunkSize, Bytes); if (!Result.Success) throw new Exception("File upload failed: " + Result.Message); BytesLeft -= ChunkSize; } } #endregion #region Upload Complete // Tell the service we have finished the upload docReturnValue = _documentServiceClient.DocumentUploadComplete(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId); #endregion if (File.Exists(fileName)) { File.Delete(fileName); } } else { docDetails.Id = Convert.ToInt32(Session[SessionName.DocumentId]); if (_ccCreatedDate.DateText.Length > 0) { docDetails.CreatedDate = Convert.ToDateTime(_ccCreatedDate.DateText); } try { docReturnValue = _documentServiceClient.EditMatterDocumentDetails(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, docDetails); } catch (Exception ex) { _lblError.Text = ex.Message; } } if (docReturnValue != null) { if (docReturnValue.Success) { if (docReturnValue.Document != null) { if (_editMode == false) { Session[SessionName.DocumentId] = docReturnValue.Document.Id; _editMode = true; } DisplayDocumentDetails(); _lblError.Text = "Document information saved successfully."; _lblError.CssClass = "successMessage"; if (_DdlFolder.SelectedItem.Text.Trim() != "General") { //docDetails.IsFolder = true; WSDocManagement.DocSvc _docSvc = new WSDocManagement.DocSvc(); if (_editMode) { _docSvc.SaveToDocAttributes(docDetails.Id, _DdlFolder.SelectedItem.Text, 20); } else { _docSvc.SaveToDocAttributes(_docSvc.GetNewestDocId(), _DdlFolder.SelectedItem.Text, 20); } } } } else { _lblError.Text = "Document information not saved.<br />" + docReturnValue.Message; _lblError.CssClass = "errorMessage"; } } } catch (Exception ex) { _lblError.Text = ex.Message; } finally { if (_documentServiceClient != null) { _documentServiceClient.Close(); } if (Session[SessionName.DocumentId] != null) { Session[SessionName.DocumentId] = null; } if (ItemChanged != null) { OnItemChanged(e); } } }