private void BuildAndDownLoadDocument(RealpageData.Resident res, string folder, ClientEntry cle) { AuthDTO auth = GetAuth(cle); var client = new RPXServiceClient(); client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 00); try { var req = new BuildCollectionDocumentsRequest() { reshid = res.ReshID }; var resp = client.buildcollectiondocuments(auth, req); txtResponse.Text = resp.ToString(); var fileSizeNode = resp.Descendants("filesize").FirstOrDefault(); int fileSizeVal = 0; if (fileSizeNode != null) { fileSizeVal = Convert.ToInt32(fileSizeNode.Value); } if (fileSizeVal == 0) { // AddMessage("No files to download for site " + res.SiteID + " Tenant Reshid " + res.ReshID + " Name: " + res.FirstName + " " + res.LastName ); return; } var reqDL = new DownloadCollectionDocumentRequest() { reshid = res.ReshID }; string returnDoc = client.downloadcollectiondocument(auth, reqDL).Value; var filename = folder + @"\" + cle.RrsId + "_" + cle.SiteId + "_" + res.ReshID + "_" + StripNumber(res.LastName) + "_" + res.FirstName + "_" + DateTime.Now.ToString("MMddyyyy_HHmm") + ".pdf"; FileStream wFile = new FileStream(filename, FileMode.Create); byte[] buffer; buffer = Convert.FromBase64String(returnDoc); wFile.Write(buffer, 0, buffer.Length); wFile.Close(); AddMessage("File " + filename + " Has been created ; filesize " + fileSizeVal); } catch (Exception ex) { Log.Error("Error Creating File\n" + ex); MessageBox.Show("Error Creating File\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDlCollectionDocument_Click(object sender, EventArgs e) { KeyValuePair<string, string> selectedPair = (KeyValuePair<string,string>) cboSiteList.SelectedItem; var folder = txtColl.Text; var siteId = selectedPair.Key.Split('_')[1]; var cboRrsId = selectedPair.Value; int resId = 0; int.TryParse(txtReshid.Text.Trim(), out resId); if (resId == 0 || string.IsNullOrEmpty(cboRrsId)) { MessageBox.Show("Please select a siteId and enter an ReshId", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } tabCtl.SelectTab("tabRetrieval"); ClientEntry cle = GetClientEntry(siteId); AuthDTO auth = GetAuth(cle); var client = new RPXServiceClient(); client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 00); try { var req = new BuildCollectionDocumentsRequest() { reshid = resId }; var resp = client.buildcollectiondocuments(auth, req); txtResponse.Text = resp.ToString(); var fileSizeNode = resp.Descendants("filesize").FirstOrDefault(); int fileSizeVal = 0; if (fileSizeNode != null) { fileSizeVal = Convert.ToInt32(fileSizeNode.Value); } if (fileSizeVal == 0) { AddMessage("No files to download"); return; } var dirOut = GetOutputFolder(folder, cle); var dlFile = dirOut + @"\" + cle.RrsId + "_" + siteId + "_" + resId + "_AdHoc_" + DateTime.Now.ToString("MMddyyyy_HHmm") + ".pdf"; var reqDL = new DownloadCollectionDocumentRequest() { reshid = resId }; string returnDoc = client.downloadcollectiondocument(auth, reqDL).Value; FileStream wFile = new FileStream(dlFile, FileMode.Create); byte[] buffer; buffer = Convert.FromBase64String(returnDoc); wFile.Write(buffer, 0, buffer.Length); wFile.Close(); AddMessage("File has been created as " + dlFile + "; FileSize is " + fileSizeVal); } catch (Exception ex) { Log.Error("Error Creating File\n" + ex); MessageBox.Show("Error Creating File\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }