public static CswNbtChemWatchRequest GetSDSDocument(ICswResources CswResources, string filename) { CswNbtChemWatchRequest Return = new CswNbtChemWatchRequest(); CswNbtResources NbtResources = (CswNbtResources)CswResources; string errorMsg; if (_authenticate(NbtResources, out errorMsg)) { DocumentServiceClient cwDocClient = new DocumentServiceClient(); cwDocClient.Endpoint.Behaviors.Add(_cookieBehavior); Stream DocStream = null; try { DocStream = cwDocClient.GetDocumentContent(filename); Return.SDSDocument = DocStream; } catch (Exception ex) { Return.Message = ex.Message; } } else { throw new CswDniException(CswEnumErrorType.Error, "There was a problem authenticating with ChemWatch", errorMsg); } return(Return); }
/// <summary> /// Gets the documents for the matter. /// </summary> public DocumentSearchItem[] GetSearchForMatterDocuments(int startRow, int pageSize, string searchText, Int32 fileType, Boolean deepSearch, Boolean matchCase, Boolean searchSubFolders) { DocumentServiceClient documentService = new DocumentServiceClient(); DocumentSearchItem[] matterDocs = null; try { Guid logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId; DocumentSearchCriteria criteria = new DocumentSearchCriteria(); criteria.DocumentType = fileType; criteria.IsDeepSearch = deepSearch; criteria.IsMatchCase = matchCase; criteria.IsSubFolderSearch = searchSubFolders; criteria.SearchString = searchText; if (HttpContext.Current.Session[SessionName.ProjectId] != null) { DocumentSearchReturnValue returnValue = documentService.GetMatterDocumentForDeepSearch(logonId, (Guid)HttpContext.Current.Session[SessionName.ProjectId], criteria); if (returnValue != null) { if (returnValue.Success) { if (returnValue.Document != null) { matterDocs = returnValue.Document.Rows; _matterDocumentRowCount = returnValue.Document.Rows.Length; } } else { throw new Exception(returnValue.Message); } } } else { throw new Exception("No Project Id found."); } } catch (Exception ex) { throw ex; } finally { if (documentService != null) { if (documentService.State != System.ServiceModel.CommunicationState.Faulted) { documentService.Close(); } } } return(matterDocs); }
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; } }
/// <summary> /// Gets the documents for the matter. /// </summary> public DocumentSearchItem[] GetSearchForMatterDocuments(int startRow, int pageSize, string searchText, Int32 fileType, Boolean deepSearch, Boolean matchCase, Boolean searchSubFolders) { DocumentServiceClient documentService = new DocumentServiceClient(); DocumentSearchItem[] matterDocs = null; try { Guid logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId; DocumentSearchCriteria criteria = new DocumentSearchCriteria(); criteria.DocumentType = fileType; criteria.IsDeepSearch = deepSearch; criteria.IsMatchCase = matchCase; criteria.IsSubFolderSearch = searchSubFolders; criteria.SearchString = searchText; if (HttpContext.Current.Session[SessionName.ProjectId] != null) { DocumentSearchReturnValue returnValue = documentService.GetMatterDocumentForDeepSearch(logonId, (Guid)HttpContext.Current.Session[SessionName.ProjectId], criteria); if (returnValue != null) { if (returnValue.Success) { if (returnValue.Document != null) { matterDocs = returnValue.Document.Rows; _matterDocumentRowCount = returnValue.Document.Rows.Length; } } else { throw new Exception(returnValue.Message); } } } else { throw new Exception("No Project Id found."); } } catch (Exception ex) { throw ex; } finally { if (documentService != null) { if (documentService.State != System.ServiceModel.CommunicationState.Faulted) documentService.Close(); } } return matterDocs; }
/// <summary> /// Gets the documents for the matter. /// </summary> public DocumentSearchItem[] GetMatterDocuments(int startRow, int pageSize) { DocumentServiceClient documentService = new DocumentServiceClient(); DocumentSearchItem[] matterDocs = null; try { Guid logonId = ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId; CollectionRequest collectionRequest = new CollectionRequest(); collectionRequest.StartRow = startRow; collectionRequest.RowCount = pageSize; collectionRequest.ForceRefresh = true; if (Session[SessionName.ProjectId] != null) { DocumentSearchReturnValue returnValue = documentService.MatterDocumentSearch(logonId, (Guid)Session[SessionName.ProjectId], ""); if (returnValue != null) { if (returnValue.Success) { if (returnValue.Document != null) { matterDocs = returnValue.Document.Rows; _matterDocumentRowCount = returnValue.Document.Rows.Length; } } else { throw new Exception(returnValue.Message); } } } else { throw new Exception("No Project Id found."); } return(matterDocs); } catch (Exception ex) { throw ex; } finally { if (documentService != null) { if (documentService.State != System.ServiceModel.CommunicationState.Faulted) { documentService.Close(); } } } }
/// <summary> /// Gets the documents for the matter. /// </summary> public DocumentSearchItem[] GetMatterDocuments(int startRow, int pageSize, string sortBy) { DocumentServiceClient documentService = new DocumentServiceClient(); DocumentSearchItem[] matterDocs = null; try { Guid logonId = ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId; CollectionRequest collectionRequest = new CollectionRequest(); collectionRequest.StartRow = startRow; collectionRequest.RowCount = pageSize; collectionRequest.ForceRefresh = true; if (Session[SessionName.ProjectId] != null) { DocumentSearchReturnValue returnValue = documentService.MatterDocumentSearch(logonId, (Guid)Session[SessionName.ProjectId], sortBy); if (returnValue != null) { if (returnValue.Success) { if (returnValue.Document != null) { matterDocs = returnValue.Document.Rows; _matterDocumentRowCount = returnValue.Document.Rows.Length; } } else { throw new Exception(returnValue.Message); } } } else { throw new Exception("No Project Id found."); } return matterDocs; } catch (Exception ex) { throw ex; } finally { if (documentService != null) { if (documentService.State != System.ServiceModel.CommunicationState.Faulted) documentService.Close(); } } }
/// <summary> /// Gets the matters for the client. /// </summary> private void BindDocumentTypes() { DocumentServiceClient documentTypeService = new DocumentServiceClient(); try { CollectionRequest collectionRequest = new CollectionRequest(); collectionRequest.StartRow = 0; DocumentTypeSearchCriteria docTypeCriteria = new DocumentTypeSearchCriteria(); docTypeCriteria.DocTypeIDs = "1, 3"; FileTypeReturnValue fileTypeReturnValue = documentTypeService.GetFileTypes(((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId); if (fileTypeReturnValue.Success) { if (fileTypeReturnValue.FileType != null) { _ddlFileType.DataSource = fileTypeReturnValue.FileType; _ddlFileType.DataTextField = "FileDescription"; _ddlFileType.DataValueField = "FileDescription"; _ddlFileType.DataBind(); } } else { throw new Exception(fileTypeReturnValue.Message); } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; _lblError.CssClass = "errorMessage"; } catch (Exception ex) { _lblError.Text = ex.Message; _lblError.CssClass = "errorMessage"; } finally { if (documentTypeService.State != System.ServiceModel.CommunicationState.Faulted) { documentTypeService.Close(); } } _ddlFileType.SelectedIndex = -1; _ddlFileType.SelectedIndex = _ddlFileType.Items.Count - 1; }
public static CswNbtChemWatchRequest SDSDocumentSearch(ICswResources CswResources, CswNbtChemWatchRequest Request) { CswNbtChemWatchRequest Return = new CswNbtChemWatchRequest(); CswNbtResources NbtResources = (CswNbtResources)CswResources; string errorMsg; if (_authenticate(NbtResources, out errorMsg)) { DocumentServiceClient cwDocClient = new DocumentServiceClient(); cwDocClient.Endpoint.Behaviors.Add(_cookieBehavior); //every service client needs to share this DocumentRequest DocumentRequest = new DocumentRequest(); List <int> CountryIdsList = Request.Countries.selected.Select(ListItem => CswConvert.ToInt32(ListItem.Id)).ToList(); int[] CountryIdsArray = CountryIdsList.ToArray(); DocumentRequest.CountryCode = CountryIdsArray; List <int> LanguageIdsList = Request.Languages.selected.Select(ListItem => CswConvert.ToInt32(ListItem.Id)).ToList(); int[] LanguageIdsArray = LanguageIdsList.ToArray(); DocumentRequest.LanguageCode = LanguageIdsArray; DocumentRequest.MaterialId = CswConvert.ToString(Request.ChemWatchMaterialId); DocumentRequest.IsShowOwn = false; DocumentRequest.IsLatest = true; DocumentRequest.ShowOnlyGold = false; DocumentRequest.PageNumber = 1; DocumentRequest.PageSize = 50; DocumentRequest.HideGold = true; DocumentRequest.Gid = Request.Supplier; ListResultOfDocument DocumentList = cwDocClient.GetDocumentsByMaterialId(DocumentRequest); foreach (Document Doc in DocumentList.Rows) { ChemWatchSDSDoc SDSDoc = new ChemWatchSDSDoc(); SDSDoc.Language = Doc.LanguageCode; SDSDoc.Country = Doc.CountryCode; SDSDoc.FileName = Doc.FileName.Length > 0 ? Doc.FileName : String.Empty; SDSDoc.ExternalUrl = Doc.ExternalUrl; Return.SDSDocuments.Add(SDSDoc); } } else { throw new CswDniException(CswEnumErrorType.Error, "There was a problem authenticating with ChemWatch", errorMsg); } return(Return); }
public RenewalPolicyDetailed GetRenewalPolicyDetailsByPolId(string polId) { var policy = PolicyData.GetRenewalPolicies(false).SingleOrDefault(p => p.PolicyId == polId); if (policy != null && !string.IsNullOrEmpty(policy.PolicyId)) { using (var client = new DocumentServiceClient()) { policy.RelatedDocumentCount = client.GetDocumentsCountForPolicy(policy.PolicyId); } var renewalCalc = PolicyDataService.GetPolicyRenewalCalc(policy.PolicyId); policy.IsRenewable = renewalCalc.IsRenewable; } return(policy); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _grdDocFiles_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "select") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkEdit") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); Session[SessionName.DocumentId] = docId; Response.Redirect("~/Pages/DocMgmt/ImportDocument.aspx", true); } } else if (e.CommandName == "reupload") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkReupload") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); Session[SessionName.DocumentId] = docId; Response.Redirect("~/Pages/DocMgmt/ReuploadDocument.aspx", true); } } else if (e.CommandName == "fileDownload") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkFileDownload") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { Guid ProjectId = DataConstants.DummyGuid; StartDocumentDownloadReturnValue Header; if (!string.IsNullOrEmpty(Convert.ToString(Session[SessionName.ProjectId]))) { ProjectId = new Guid(Convert.ToString(Session[SessionName.ProjectId])); } #region Start Download try { Header = _documentServiceClient.StartDocumentDownloadForMatter(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, ProjectId, docId); } catch (Exception ex) { throw ex; } #endregion if (Header != null) { if (!Header.Success) { _lblError.CssClass = "errorMessage"; _lblError.Text = Header.Message; return; } if (!Directory.Exists(Path.Combine(Server.MapPath("."), "Download"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("."), "Download")); } long BytesLeft = Header.Size; string downloadFolderPath = Path.Combine(Server.MapPath("."), "Download"); string FileName = Path.Combine(downloadFolderPath, Header.FileName); try { #region Download Chunk by Chunk // Open the file using (FileStream FileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { while (BytesLeft > 0) { // Download a chunk DownloadChunkReturnValue Chunk = _documentServiceClient.DocumentDownloadChunk( ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId, FileStream.Position); if (!Chunk.Success) throw new Exception("File download failed: " + Chunk.Message); // Write the chunk to the file FileStream.Write(Chunk.Bytes, 0, Chunk.ChunkSize); BytesLeft -= Chunk.ChunkSize; } } #endregion #region Download Complete // Tell the service we have finished downloading _documentServiceClient.DocumentDownloadComplete(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId); #endregion // Check the file size if (new FileInfo(FileName).Length != Header.Size) throw new Exception("File download failed, file size is wrong"); // Make a hash of the file byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(FileName); // Check the hash matches that from the server if (!FileTransferHash.CheckHash(LocalHash, Header.Hash)) { throw new Exception("File download failed, document checksum does not match"); } // Set the file modified date File.SetLastWriteTime(FileName, Header.ModifiedDate); try { //string jscript = "HideProgress();window.open('DocumentView.aspx?file={0}&path={1}','FileDownload','height=200,width=400,status=no,toolbar=no,menubar=no,left=0,top=0');"; string jscript = "HideProgress(); GetDocument('DocumentView.aspx?file={0}&path={1}');"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), string.Format(jscript, HttpUtility.UrlEncode(new FileInfo(FileName).Name), HttpUtility.UrlEncode(FileName)), true); } catch (Exception ex) { throw ex; } } catch { // Download failed so delete file being downloaded File.Delete(FileName); throw; } } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; _lblError.CssClass = "errorMessage"; } catch (Exception ex) { _lblError.CssClass = "errorMessage"; _lblError.Text = ex.Message; } finally { if (_documentServiceClient != null) { if (_documentServiceClient.State != System.ServiceModel.CommunicationState.Faulted) _documentServiceClient.Close(); } } } } }
/// <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(); } } } }
/// <summary> /// Gets the documents for the matter. /// </summary> public DocumentSearchItem[] GetMatterDocuments(int startRow, int pageSize) { DocumentServiceClient documentService = new DocumentServiceClient(); DocumentSearchItem[] matterDocs = null; try { Guid logonId = ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId; CollectionRequest collectionRequest = new CollectionRequest(); collectionRequest.StartRow = startRow; collectionRequest.RowCount = pageSize; collectionRequest.ForceRefresh = true; if (Session[SessionName.ProjectId] != null) { DocumentSearchReturnValue returnValue = documentService.MatterDocumentSearch(logonId, (Guid)Session[SessionName.ProjectId], ""); if (returnValue != null) { if (returnValue.Success) { if (returnValue.Document != null) { List <DocumentSearchItem> _Dsi = new List <DocumentSearchItem>(); List <string> AppFiles = ApprovedFiles(); foreach (DocumentSearchItem _Dr in returnValue.Document.Rows) { if (AppFiles.Contains(_Dr.FileName.Trim())) { _Dsi.Add(_Dr); } } matterDocs = _Dsi.ToArray(); //_LblRowCount.Text = _Dsi.Count.ToString(); //matterDocs = returnValue.Document.Rows; //_matterDocumentRowCount = returnValue.Document.Rows.Length; } } else { throw new Exception(returnValue.Message); } } } else { throw new Exception("No Project Id found."); } return(matterDocs); } catch (Exception ex) { throw ex; } finally { if (documentService != null) { documentService.Close(); } } }
/// <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(); } } } }
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) { _documentServiceClient.Close(); } if (DocReUpload != null) { OnDocReUpload(e); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _grdDocFiles_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "select") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkEdit") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); Session[SessionName.DocumentId] = docId; Response.Redirect("~/DocumentManagement/ImportDocument.aspx", true); } } else if (e.CommandName == "reupload") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkReupload") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); Session[SessionName.DocumentId] = docId; Response.Redirect("~/DocumentManagement/ReuploadDocument.aspx", true); } } else if (e.CommandName == "fileDownload") { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (row.Cells[0].FindControl("_linkFileDownload") != null) { int rowId = ((GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer).RowIndex; int docId = Convert.ToInt32(_grdDocFiles.DataKeys[rowId].Values["Id"].ToString()); DocumentServiceClient _documentServiceClient = new DocumentServiceClient(); try { Guid ProjectId = DataConstants.DummyGuid; StartDocumentDownloadReturnValue Header; if (!string.IsNullOrEmpty(Convert.ToString(Session[SessionName.ProjectId]))) { ProjectId = new Guid(Convert.ToString(Session[SessionName.ProjectId])); } #region Start Download try { Header = _documentServiceClient.StartDocumentDownloadForMatter(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, ProjectId, docId); } catch (Exception ex) { throw ex; } #endregion if (Header != null) { if (!Header.Success) { _lblError.CssClass = "errorMessage"; _lblError.Text = Header.Message; return; } if (!Directory.Exists(Path.Combine(Server.MapPath("."), "Download"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("."), "Download")); } long BytesLeft = Header.Size; string downloadFolderPath = Path.Combine(Server.MapPath("."), "Download"); string FileName = Path.Combine(downloadFolderPath, Header.FileName); try { #region Download Chunk by Chunk // Open the file using (FileStream FileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { while (BytesLeft > 0) { // Download a chunk DownloadChunkReturnValue Chunk = _documentServiceClient.DocumentDownloadChunk( ((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId, FileStream.Position); if (!Chunk.Success) { throw new Exception("File download failed: " + Chunk.Message); } // Write the chunk to the file FileStream.Write(Chunk.Bytes, 0, Chunk.ChunkSize); BytesLeft -= Chunk.ChunkSize; } } #endregion #region Download Complete // Tell the service we have finished downloading _documentServiceClient.DocumentDownloadComplete(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, Header.TransferId); #endregion // Check the file size if (new FileInfo(FileName).Length != Header.Size) { throw new Exception("File download failed, file size is wrong"); } // Make a hash of the file byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(FileName); // Check the hash matches that from the server if (!FileTransferHash.CheckHash(LocalHash, Header.Hash)) { throw new Exception("File download failed, document checksum does not match"); } // Set the file modified date File.SetLastWriteTime(FileName, Header.ModifiedDate); try { //string jscript = "HideProgress();window.open('DocumentView.aspx?file={0}&path={1}','FileDownload','height=200,width=400,status=no,toolbar=no,menubar=no,left=0,top=0');"; string jscript = "HideProgress(); GetDocument('" + AppFunctions.GetASBaseUrl() + "/Pages/DocMgmt/DocumentView.aspx?file={0}&path={1}');"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), string.Format(jscript, HttpUtility.UrlEncode(new FileInfo(FileName).Name), HttpUtility.UrlEncode(FileName)), true); } catch (Exception ex) { throw ex; } } catch { // Download failed so delete file being downloaded File.Delete(FileName); throw; } } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; _lblError.CssClass = "errorMessage"; } catch (Exception ex) { _lblError.CssClass = "errorMessage"; _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; } }
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; } }
/// <summary> /// Gets the matters for the client. /// </summary> private void BindDocumentTypes() { DocumentServiceClient documentTypeService = new DocumentServiceClient(); try { CollectionRequest collectionRequest = new CollectionRequest(); collectionRequest.StartRow = 0; DocumentTypeSearchCriteria docTypeCriteria = new DocumentTypeSearchCriteria(); docTypeCriteria.DocTypeIDs = "1, 3"; FileTypeReturnValue fileTypeReturnValue = documentTypeService.GetFileTypes(((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId); if (fileTypeReturnValue.Success) { if (fileTypeReturnValue.FileType != null) { _ddlFileType.DataSource = fileTypeReturnValue.FileType; _ddlFileType.DataTextField = "FileDescription"; _ddlFileType.DataValueField = "FileDescription"; _ddlFileType.DataBind(); } } else { throw new Exception(fileTypeReturnValue.Message); } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; _lblError.CssClass = "errorMessage"; } catch (Exception ex) { _lblError.Text = ex.Message; _lblError.CssClass = "errorMessage"; } finally { if (documentTypeService.State != System.ServiceModel.CommunicationState.Faulted) documentTypeService.Close(); } _ddlFileType.SelectedIndex = -1; _ddlFileType.SelectedIndex = _ddlFileType.Items.Count - 1; }
public RenewalPolicyDetailed GetRenewalPolicyDetailsByPolId(string polId) { var policy = PolicyData.GetRenewalPolicies(false).SingleOrDefault(p => p.PolicyId == polId); if (policy != null && !string.IsNullOrEmpty(policy.PolicyId)) { using (var client = new DocumentServiceClient()) { policy.RelatedDocumentCount = client.GetDocumentsCountForPolicy(policy.PolicyId); } var renewalCalc = PolicyDataService.GetPolicyRenewalCalc(policy.PolicyId); policy.IsRenewable = renewalCalc.IsRenewable; } return policy; }
/// <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(); } } }