Skip to content

Instantly share code, notes, and snippets.

@moaschterle
Created August 9, 2013 13:29
Show Gist options
  • Save moaschterle/6193586 to your computer and use it in GitHub Desktop.
Save moaschterle/6193586 to your computer and use it in GitHub Desktop.
//Methode die mir in Docuware File mit Metadaten Uploaded
public static GapiResponse UploadFile(List<DWField> DWIndices, string documentpath, string filecabinetguid)
{
int docid = 0;
try
{
//Vorher kontrollieren ob _GapiClient instanziert ist
IFileCabinet filecabinet = _gapiClient.Organization.GetFileCabinet(new Guid(filecabinetguid));
IFileCabinetStorageCommand myfilecommand = filecabinet.Commands.newStorage();
IUnfiledDocument mydocument = _gapiClient.CreateDocument(documentpath);
IModifyMetaDataCommand metadata = mydocument.Commands.newModifyMetaData();
foreach (DWField myfield in DWIndices)
{
metadata.SetFieldData(myfield.FieldIndex, FieldObjectValue(myfield.FieldIndex, myfield.FieldValue));
}
metadata.Execute();
//Delete File on Filesystem after Storage
myfilecommand.ExecuteEx(mydocument, true);
docid = myfilecommand.DocID;
return new GapiResponse { RuturnDocId = docid };
}
catch (Exception ex)
{
return new GapiResponse { ErrorGapi = true, ReturnGapiMessage = ex.Message, RuturnDocId = docid };
}
}
//Klasse DWField (für Insert)
public class DWField
{
public int FieldIndex { get; set; }
public string FieldValue { get; set; }
}
//Helper Methode anhand des Werts des Indices kann man auf den Typ in DW schliessen
public static object FieldObjectValue(int fieldID, string fieldValue)
{
//von 64 bis 95 e una data
if (fieldID >= 64 && fieldID <= 95)
{
return Convert.ToDateTime(fieldValue);
}
//von ist numeric
if (fieldID >= 96 && fieldID <= 127)
{
return Convert.ToInt32(fieldValue);
}
return fieldValue.ToString();
}
//eigentlicher Insert vom Client aus
string filecabinetguid = "c9c767f4-3427-4a76-bf01-ba741f153319";
string documentpath = mydocumentpath;
List<DWField> myindices = new List<DWField>();
myindices.Add(new DWField { FieldIndex = 6, FieldValue = "smg" });
myindices.Add(new DWField { FieldIndex = 65, FieldValue = "2013-08-07" });
myindices.Add(new DWField { FieldIndex = 1048768, FieldValue = "9999999" });
myindices.Add(new DWField { FieldIndex = 96, FieldValue = "55860" });
GapiResponse response = DocuwareHelper.UploadFile(myindices, documentpath, filecabinetguid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment