using DocuWare.Platform.ServerClient; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace MarquetteResumeAttach { public partial class Form1 : Form { public static ServiceConnection DWConn; static List migIDList = new List(); static List newIDList = new List(); public Form1() { InitializeComponent(); } private void Main() { ReadCSV(txtCSVPath.Text); Organization org = DWConn.Organizations[0]; FileCabinet cabinet = GetFileCabinetByName(org, cboxFileCabinets.SelectedItem.ToString()); for (int i = 0; i < migIDList.Count; i++) { MergeDocuments(cabinet, new List() { newIDList[i], migIDList[i] }); } lblStatus.Text = "DONE!"; } private void ConnectToDocuWare() { try { DWConn = ServiceConnection.Create(new Uri("https://servername/docuware/platform"), "username", "password"); var org = DWConn.Organizations[0]; List fileCabinet = org.GetFileCabinetsFromFilecabinetsRelation().FileCabinet; foreach (var fc in fileCabinet) { cboxFileCabinets.Items.Add(fc.Name); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public static void ReadCSV(string fileName) { using (var reader = new StreamReader(fileName)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); migIDList.Add(Convert.ToInt32(values[0])); newIDList.Add(Convert.ToInt32(values[1])); } } } public static FileCabinet GetFileCabinetByName(Organization org, string fileCabinetName) { try { List fileCabinets = org.GetFileCabinetsFromFilecabinetsRelation().FileCabinet; FileCabinet fileCabinet = fileCabinets.Single(f => f.Name.Trim().ToUpper() == fileCabinetName.Trim().ToUpper()); return fileCabinet; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } } public static Document MergeDocuments(FileCabinet cabinet, List docIds) { try { Document mergedDocument = cabinet.PutToContentMergeOperationRelationForDocument ( new ContentMergeOperationInfo() { Documents = docIds, Operation = ContentMergeOperation.Clip, Force = true } ); return mergedDocument; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } } private void btnBrowse_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { DialogResult result = ofd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(ofd.FileName)) { txtCSVPath.Text = ofd.FileName; } } } private void btnConnect_Click(object sender, EventArgs e) { ConnectToDocuWare(); } private void btnMain_Click(object sender, EventArgs e) { Main(); } } }