private void DisplayDetails() { try { DocumentServiceClient docService = new DocumentServiceClient(); try { DocumentReturnValue docReturnValue = docService.GetDocumentDetails(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, (Guid)Session[SessionName.ProjectId], Convert.ToInt32(Session[SessionName.DocumentId])); if (docReturnValue.Success) { if (docReturnValue.Document != null) { _lblErrorReupload.Text = string.Empty; string fileName = docReturnValue.Document.FileName.Substring(docReturnValue.Document.FileName.LastIndexOf(@"\") + 1); _hdnDocFileName.Value = fileName; _txtNotes.Text = docReturnValue.Document.Notes; if (docReturnValue.Document.UseVersioning) { _lblFileNameNote.Text = "Note: File should be uploaded with the file name '" + fileName + "'"; } else { _lblFileNameNote.Text = "Note: you cannot reupload this document until you've enabled versioning."; _btnSaveReupload.Enabled = false; _btnResetReupload.Enabled = false; } } } else { throw new Exception(docReturnValue.Message); } } catch (Exception ex) { throw ex; } finally { if (docService != null) { docService.Close(); } } } catch (Exception ex) { _btnResetReupload.Enabled = false; _btnSaveReupload.Enabled = false; throw ex; } }
public DocumentReturnValue GetDocumentDetails(HostSecurityToken oHostSecurityToken, Guid projectId, int docId) { DocumentReturnValue ReturnValue = null; if (Functions.ValidateIWSToken(oHostSecurityToken)) { oDocumentService = new DocumentService(); ReturnValue = oDocumentService.GetDocumentDetails(Functions.GetLogonIdFromToken(oHostSecurityToken), projectId, docId); } else { ReturnValue = new DocumentReturnValue(); ReturnValue.Success = false; ReturnValue.Message = "Invalid Token"; } return(ReturnValue); }
/// <summary> /// Save Document to document server and also save details to the database /// This method requires to work with actual files, the reason is /// If the existing document is not encrypted, and if user updates the document details by setting /// Encryption flag to true, then the actual document is to be encrypted. /// </summary> /// <param name="oHostSecurityToken"></param> /// <param name="docSearchItem"></param> /// <returns></returns> public DocumentReturnValue EditMatterDocumentDetails(HostSecurityToken oHostSecurityToken, DocumentSearchItem docSearchItem) { DocumentReturnValue ReturnValue = null; if (Functions.ValidateIWSToken(oHostSecurityToken)) { oDocumentService = new DocumentService(); ReturnValue = oDocumentService.EditMatterDocumentDetails(Functions.GetLogonIdFromToken(oHostSecurityToken), docSearchItem); } else { ReturnValue = new DocumentReturnValue(); ReturnValue.Success = false; ReturnValue.Message = "Invalid Token"; } return(ReturnValue); }
/// <summary> /// Document Upload Complete /// </summary> /// <param name="oHostSecurityToken"></param> /// <param name="TransferId"></param> /// <param name="docSearchItem"></param> /// <returns></returns> public DocumentReturnValue DocumentUploadComplete(HostSecurityToken oHostSecurityToken, Guid TransferId) { DocumentReturnValue ReturnValue = null; if (Functions.ValidateIWSToken(oHostSecurityToken)) { oDocumentService = new DocumentService(); ReturnValue = oDocumentService.DocumentUploadComplete(Functions.GetLogonIdFromToken(oHostSecurityToken), TransferId); } else { ReturnValue = new DocumentReturnValue(); ReturnValue.Success = false; ReturnValue.Message = "Invalid Token"; } return(ReturnValue); }
public DocumentReturnValue GetDocumentDetails(Guid logonId, Guid projectId, int docId) { DocumentReturnValue returnValue = new DocumentReturnValue(); try { // Get the logged on user from the current logons and add their // ApplicationSettings the list of concurrent sessions. Host.LoadLoggedOnUser(logonId); try { Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid); switch (UserInformation.Instance.UserType) { case DataConstants.UserType.Staff: // Can do everything case DataConstants.UserType.Client: case DataConstants.UserType.ThirdParty: if (!SrvMatterCommon.WebAllowedToAccessMatter(projectId)) throw new Exception("Access denied"); // Must check that document belongs to the matter // (otherwise any docId could be passed and the matter security check above is meaningless) this.CheckDocumentBelongsToMatter(projectId, docId); break; default: throw new Exception("Access denied"); } DocumentSearchItem docDetails = new DocumentSearchItem(); SrvDocument srvDoc = new SrvDocument(); srvDoc.Load(docId); docDetails.Id = srvDoc.Id; docDetails.CreatedDate = srvDoc.CreationDate; docDetails.FeeEarnerId = srvDoc.FeeEarnerId; docDetails.FileName = Path.Combine(srvDoc.VolumeLocation, srvDoc.FileName); docDetails.TypeId = srvDoc.TypeId; docDetails.FileDescription = srvDoc.Description; docDetails.Notes = srvDoc.Notes; docDetails.IsPublic = srvDoc.IsPublic; docDetails.UseVersioning = srvDoc.IsUsedVersioning; docDetails.IsEncrypted = srvDoc.IsEncrypted; docDetails.IsLocked = srvDoc.IsLocked; returnValue.Document = docDetails; } finally { // Remove the logged on user's ApplicationSettings from the // list of concurrent sessions Host.UnloadLoggedOnUser(); } } catch (System.Data.SqlClient.SqlException) { returnValue.Success = false; returnValue.Message = Functions.SQLErrorMessage; } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } return returnValue; }
/// <summary> /// Save Document to document server and also save details to the database /// This method requires to work with actual files, the reason is /// If the existing document is not encrypted, and if user updates the document details by setting /// Encryption flag to true, then the actual document is to be encrypted. /// </summary> /// <param name="logonId"></param> /// <param name="docSearchItem"></param> /// <returns></returns> public DocumentReturnValue EditMatterDocumentDetails(Guid logonId, DocumentSearchItem docSearchItem) { DocumentReturnValue returnValue = new DocumentReturnValue(); string errorMessage = string.Empty; try { // Get the logged on user from the current logons and add their // ApplicationSettings the list of concurrent sessions. Host.LoadLoggedOnUser(logonId); try { Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid); switch (UserInformation.Instance.UserType) { case DataConstants.UserType.Staff: // Check permission if (!UserSecuritySettings.GetUserSecuitySettings(9)) throw new Exception("You do not have sufficient permissions to carry out this request"); break; case DataConstants.UserType.Client: case DataConstants.UserType.ThirdParty: throw new Exception("Access denied"); default: throw new Exception("Access denied"); } returnValue.Success = false; SrvDocument srvDoc = new SrvDocument(); srvDoc.Id = docSearchItem.Id; // If document details is edited then Load default values in SrvDocument srvDoc.Load(docSearchItem.Id); srvDoc.DocumentModuleId = docSearchItem.ProjectId; byte[] bytesToUpdate = new byte[0]; srvDoc.BytesToUpdate = bytesToUpdate; // Hardcoded srvDoc.Type = DmEnums.DmPMSDocType.Project; srvDoc.ApplicationId = (int)DataConstants.Application.PMS; srvDoc.FolderName = "Documents"; srvDoc.TypeId = docSearchItem.TypeId; srvDoc.Description = docSearchItem.FileDescription; srvDoc.Notes = docSearchItem.Notes; srvDoc.IsPublic=docSearchItem.IsPublic; srvDoc.IsUsedVersioning = docSearchItem.UseVersioning; srvDoc.CreationDate = docSearchItem.CreatedDate; srvDoc.IsLocked = docSearchItem.IsLocked; srvDoc.FeeEarnerId = docSearchItem.FeeEarnerId; // Don't set it while Editing Document srvDoc.VolumeId = 0; #region File Encryption if (!srvDoc.IsEncrypted && docSearchItem.IsEncrypted) { // Encrypt the file and save to the document server if (!string.IsNullOrEmpty(srvDoc.VolumeLocation)) { DmEncryptionWeb dmEncryption = new DmEncryptionWeb(); string tempDocPath = string.Empty; string savedDocPath = Path.Combine(srvDoc.VolumeLocation, srvDoc.FileName); tempDocPath = Path.Combine(Path.GetTempPath(), Path.GetFileName(srvDoc.FileName)); dmEncryption.CopyAndEncryptFile(savedDocPath, tempDocPath, false); File.Copy(tempDocPath, savedDocPath, true); File.Delete(tempDocPath); } else { throw new Exception("Upload document failed on the server."); } srvDoc.IsEncrypted = docSearchItem.IsEncrypted; } #endregion returnValue.Success = srvDoc.Save(out errorMessage); docSearchItem.Id = srvDoc.Id; docSearchItem.FileName = srvDoc.FileName; returnValue.Document = docSearchItem; } finally { // Remove the logged on user's ApplicationSettings from the // list of concurrent sessions Host.UnloadLoggedOnUser(); } } catch (System.Data.SqlClient.SqlException) { returnValue.Success = false; returnValue.Message = Functions.SQLErrorMessage; } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } return returnValue; }
/// <summary> /// Document Upload Complete /// </summary> /// <param name="logonId"></param> /// <param name="TransferId"></param> /// <param name="docSearchItem"></param> /// <returns></returns> public DocumentReturnValue DocumentUploadComplete(Guid logonId, Guid TransferId) { DocumentReturnValue ReturnValue = new DocumentReturnValue(); try { // Get the logged on user from the current logons and add their // ApplicationSettings the list of concurrent sessions. Host.LoadLoggedOnUser(logonId); try { Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid); switch (UserInformation.Instance.UserType) { case DataConstants.UserType.Staff: case DataConstants.UserType.Client: case DataConstants.UserType.ThirdParty: // Can do everything break; default: throw new Exception("Access denied"); } FileUploadInfo FileUploadInfo = FileTransfer.UploadComplete(logonId, TransferId); DocumentStorageData DocumentStorageData = Host.GetDocumentStorageData(logonId); SrvDocument srvDoc = new SrvDocument(); DocumentSearchItem docSearchItem = (DocumentSearchItem)DocumentStorageData.DocDetails; if (!DocumentStorageData.ExitingDocument) { docSearchItem.FileName = FileUploadInfo.TempFileName; string errorMessage = string.Empty; string tempUploadFilePath = string.Empty; string tempFileName = string.Empty; #region File Encryption & Saving Document to its original location try { if (!string.IsNullOrEmpty(DocumentStorageData.VolumeLocation)) { //If it wants to be encrypted, encrypt and copy to a temp directory if (docSearchItem.IsEncrypted) { tempFileName = Path.Combine(Path.GetTempPath(), Path.GetFileName(docSearchItem.FileName)); docSearchItem.FileName = tempFileName; } tempUploadFilePath = docSearchItem.FileName; FileInfo file = new FileInfo(docSearchItem.FileName); if (File.Exists(DocumentStorageData.VolumeLocation) == false) { // Attempt to copy the file. file.CopyTo(DocumentStorageData.VolumeLocation, true); } // Get New File Name docSearchItem.FileName = DocumentStorageData.FileName; // Encrypt the file and save to the document server if (docSearchItem.IsEncrypted) { string decryptFileName = DocumentStorageData.VolumeLocation; DmEncryptionWeb dmEncryption = new DmEncryptionWeb(); dmEncryption.CopyAndEncryptFile(decryptFileName, tempFileName, false); // Move encrypted File to the original Documenet Server Path File.Copy(tempFileName, DocumentStorageData.VolumeLocation, true); File.Delete(tempFileName); } } else { throw new Exception("Upload document failed on the server."); } } finally { if (!string.IsNullOrEmpty(tempUploadFilePath)) { // Delete the temp file which was created when uploaded from client if (File.Exists(tempUploadFilePath)) { File.Delete(tempUploadFilePath); } } } #endregion #region Save Document Details if (docSearchItem.ProjectId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.ProjectId; srvDoc.Type = DmEnums.DmPMSDocType.Project; } else if (docSearchItem.MemberId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.MemberId; srvDoc.Type = DmEnums.DmPMSDocType.Member; } else if (docSearchItem.OrganisationId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.OrganisationId; srvDoc.Type = DmEnums.DmPMSDocType.Org; } byte[] bytesToUpdate = new byte[0]; srvDoc.BytesToUpdate = bytesToUpdate; // Hardcoded srvDoc.ApplicationId = (int)DataConstants.Application.PMS; if (string.IsNullOrEmpty(docSearchItem.FolderName)) { srvDoc.FolderName = "Documents"; } else { srvDoc.FolderName = docSearchItem.FolderName; } srvDoc.TypeId = docSearchItem.TypeId; srvDoc.Description = docSearchItem.FileDescription; srvDoc.Notes = docSearchItem.Notes; srvDoc.IsUsedVersioning = docSearchItem.UseVersioning; srvDoc.CreationDate = docSearchItem.CreatedDate; srvDoc.IsLocked = docSearchItem.IsLocked; srvDoc.FeeEarnerId = docSearchItem.FeeEarnerId; srvDoc.IsEncrypted = docSearchItem.IsEncrypted; srvDoc.FileName = docSearchItem.FileName; srvDoc.VolumeId = DocumentStorageData.VolumeId; srvDoc.VolumeLocation = DocumentStorageData.VolumeLocation; //Document must become public for Clients and Third Party users if (UserInformation.Instance.UserType == DataConstants.UserType.Client || UserInformation.Instance.UserType == DataConstants.UserType.ThirdParty) srvDoc.IsPublic = true; else srvDoc.IsPublic = docSearchItem.IsPublic; ReturnValue.Success = srvDoc.Save(out errorMessage); if (ReturnValue.Success) { docSearchItem.Id = srvDoc.Id; docSearchItem.FileName = srvDoc.FileName; srvDoc.AddDocumentStatus(srvDoc.Id, DataConstants.DocStatus.ReadyforReview, string.Empty); } #endregion // Ensure the volume location of the saved file is returned docSearchItem.VolumeLocation = DocumentStorageData.VolumeLocation; ReturnValue.Document = docSearchItem; } else { docSearchItem.FileName = FileUploadInfo.TempFileName; ReturnValue = this.DocumentReuploaded(docSearchItem); } FileTransfer.UploadReset(logonId, TransferId); } finally { // Remove the logged on user's ApplicationSettings from the // list of concurrent sessions Host.UnloadLoggedOnUser(); } } catch (System.Data.SqlClient.SqlException) { ReturnValue.Success = false; ReturnValue.Message = Functions.SQLErrorMessage; } catch (Exception ex) { ReturnValue.Success = false; ReturnValue.Message = ex.Message; } return ReturnValue; }
/// <summary> /// Reupload document, upload updated document to the original document server location /// </summary> /// <param name="logonId"></param> /// <param name="docSearchItem"></param> /// <returns></returns> private DocumentReturnValue DocumentReuploaded(DocumentSearchItem docSearchItem) { DocumentReturnValue returnValue = new DocumentReturnValue(); string errorMessage = string.Empty; try { SrvDocument srvDoc = new SrvDocument(); srvDoc.Id = docSearchItem.Id; if (docSearchItem.ProjectId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.ProjectId; srvDoc.Type = DmEnums.DmPMSDocType.Project; } else if (docSearchItem.MemberId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.MemberId; srvDoc.Type = DmEnums.DmPMSDocType.Member; } else if (docSearchItem.OrganisationId != Guid.Empty) { srvDoc.DocumentModuleId = docSearchItem.OrganisationId; srvDoc.Type = DmEnums.DmPMSDocType.Org; } // If document details is edited then Load default values in SrvDocument srvDoc.Load(docSearchItem.Id); // Don't set it while Editing Document srvDoc.VolumeId = 0; // Hardcoded srvDoc.ApplicationId = (int)DataConstants.Application.PMS; srvDoc.FolderName = "Documents"; if (!srvDoc.IsUsedVersioning) throw new Exception("Unable to reupload document as versioning is disabled. You may rename your document and retry."); srvDoc.Notes = docSearchItem.Notes; if (returnValue.Success) { //FileStreamCreator fileStreamCreator = new FileStreamCreator(); if (!File.Exists(docSearchItem.FileName)) { throw new Exception("Document is not uploaded."); } Common dmCommon = new Common(); try { string collection = dmCommon.GetOriginalDocFilePath(docSearchItem.Id); string originalFilePath = GetValueOnIndexFromArray(collection, 0); bool isEncrypted = Convert.ToBoolean(GetValueOnIndexFromArray(collection, 1)); bool local = Convert.ToBoolean(GetValueOnIndexFromArray(collection, 2)); if (!string.IsNullOrEmpty(originalFilePath)) { // Reupload Document // If existing document is in encrypted form, then the upadted doc will also be saved in encrypted format if (dmCommon.ReuploadDoc(docSearchItem.Id, docSearchItem.FileName, isEncrypted, local)) { FileInfo file = new FileInfo(docSearchItem.FileName); if (File.Exists(originalFilePath)) { // Attempt to copy the file. file.CopyTo(originalFilePath, true); } // Save Document Details returnValue.Success = srvDoc.Save(out errorMessage); } else { returnValue.Success = false; returnValue.Message = "Reupload failed."; } } else { returnValue.Success = false; returnValue.Message = "System cannot able to find original file path location to reupload."; } } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } } } finally { if (!string.IsNullOrEmpty(docSearchItem.FileName)) { // Delete the temp file which was created when uploaded from client if (File.Exists(docSearchItem.FileName)) { File.Delete(docSearchItem.FileName); } } } return returnValue; }
/// <summary> /// Import Button Click Event /// </summary> /// <param name="sender">The sender</param> /// <param name="e">Event arguments</param> protected void _btnSave_Click(object sender, EventArgs e) { DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { 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.Now; docDetails.ModifiedDate = docDetails.CreatedDate; 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 (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; } 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"; _btnSave.Enabled = false; _btnImport.Enabled = true; } } else { _lblError.Text = "Document information not saved.<br />" + docReturnValue.Message; _lblError.CssClass = "errorMessage"; } } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; } catch (Exception ex) { _lblError.Text = ex.Message; } finally { if (_documentServiceClient != null) { if (_documentServiceClient.State != System.ServiceModel.CommunicationState.Faulted) { _documentServiceClient.Close(); } } } }
private void DisplayDocumentDetails() { try { if (_editMode == true) { _fileName.Visible = false; _trFileUpload.Style["display"] = "none"; _ccCreatedDate.Enabled = true; // Check User Security settings for LockUnlockDocuments // Which will enable/disable Locked checkbox _chkLockDocument.Enabled = ((LogonReturnValue)Session[SessionName.LogonSettings]).CanUserLockDocument; DocumentServiceClient docService = new DocumentServiceClient(); try { DocumentReturnValue docReturnValue = docService.GetDocumentDetails(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, (Guid)Session[SessionName.ProjectId], Convert.ToInt32(Session[SessionName.DocumentId])); if (docReturnValue.Success) { if (docReturnValue.Document != null) { _lblError.Text = string.Empty; _txtDocument.Text = docReturnValue.Document.FileDescription; _ccCreatedDate.DateText = docReturnValue.Document.CreatedDate.ToString("dd/MM/yyyy"); _txtNotes.Text = docReturnValue.Document.Notes; _ddlFeeEarner.SelectedIndex = -1; for (int i = 0; i < _ddlFeeEarner.Items.Count; i++) { if (GetValueOnIndexFromArray(_ddlFeeEarner.Items[i].Value, 1) == docReturnValue.Document.FeeEarnerId.ToString()) { _ddlFeeEarner.Items[i].Selected = true; } } _chkEncryptFile.Checked = Convert.ToBoolean(docReturnValue.Document.IsEncrypted); _chkLockDocument.Checked = Convert.ToBoolean(docReturnValue.Document.IsLocked); _chkUseVersioning.Checked = Convert.ToBoolean(docReturnValue.Document.UseVersioning); _chkPublic.Checked = Convert.ToBoolean(docReturnValue.Document.IsPublic); if (docReturnValue.Document.IsEncrypted) { _chkEncryptFile.Enabled = false; } } } else { throw new Exception(docReturnValue.Message); } } catch (Exception ex) { throw ex; } finally { if (docService != null) { if (docService.State != System.ServiceModel.CommunicationState.Faulted) { docService.Close(); } } } } } catch (Exception ex) { _btnReset.Enabled = false; _btnSave.Enabled = false; throw ex; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _btnSaveReupload_Click(object sender, EventArgs e) { string fileName = string.Empty; DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { DocumentSearchItem docDetails = new DocumentSearchItem(); #region Upload File to Application Server if (_fileName.PostedFile != null) { if (!string.IsNullOrEmpty(_fileName.PostedFile.FileName)) { if (!CheckFileTypeExtension()) { _lblErrorReupload.Text = UploadFileTypesErrorMessage; return; } if (string.IsNullOrEmpty(_hdnDocFileName.Value)) { _lblErrorReupload.Text = "Existing file name to compare does not exists."; return; } if (Convert.ToString(_hdnDocFileName.Value) != _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1)) { _lblErrorReupload.Text = "File should be uploaded with the file name '" + _hdnDocFileName.Value + "'"; 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)); docDetails.FileName = Server.MapPath(".") + "/Upload/" + _fileName.PostedFile.FileName.Substring(_fileName.PostedFile.FileName.LastIndexOf("\\") + 1); } else { _lblErrorReupload.Text = "Please select document."; return; } } #endregion DocumentReturnValue docReturnValue = null; StartDocumentUploadReturnValue Header; #region Load Data docDetails.ProjectId = (Guid)Session[SessionName.ProjectId]; // Document Type is General docDetails.TypeId = 1; docDetails.Id = Convert.ToInt32(Session[SessionName.DocumentId]); docDetails.Notes = _txtNotes.Text; fileName = docDetails.FileName; #endregion if (string.IsNullOrEmpty(fileName)) { _lblErrorReupload.Text = "Please select document."; return; } FileInfo FInfo = new FileInfo(fileName); // Create a hash of the file byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(fileName); #region Start Upload File try { Header = _documentServiceClient.StartExistingDocumentUploadForMatter(((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) { _lblErrorReupload.CssClass = "errorMessage"; _lblErrorReupload.Text = Header.Message; return; } } #endregion #region Upload 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 & Save Document Details docReturnValue = _documentServiceClient.DocumentUploadComplete(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId); #endregion if (docReturnValue != null) { if (docReturnValue.Success) { if (File.Exists(fileName)) { File.Delete(fileName); } if (docReturnValue.Success) { _lblErrorReupload.Text = "Document information saved successfully."; _lblErrorReupload.CssClass = "successMessage"; } else { _lblErrorReupload.Text = docReturnValue.Message; _lblErrorReupload.CssClass = "errorMessage"; } } else { _lblErrorReupload.Text = "Document information not saved.<br />" + docReturnValue.Message; _lblErrorReupload.CssClass = "errorMessage"; } } } catch (Exception ex) { _lblErrorReupload.Text = ex.Message; _lblErrorReupload.CssClass = "errorMessage"; } finally { if (_documentServiceClient != null) { if (_documentServiceClient.State != System.ServiceModel.CommunicationState.Faulted) { _documentServiceClient.Close(); } } } }