ToolOperationsUploadFile Method |
Upload a file that can be use in other operations such as integration.
Namespace:
Cobra.WebService.ClientAPI.Application.Tools
Assembly:
Cobra.WebService.ClientAPI (in Cobra.WebService.ClientAPI.dll) Version: 8.3.715.2595 (8.3.0715.2595)
Syntax Exceptions Exception | Condition |
---|
InvalidOperationException | Thrown when state of the instance of the CobraServices that generated the current ToolOperations is not in opened state. |
Remarks
Files using the following extensions are considered to be malicious and are blocked from being uploaded:
.ade, .adp, .app, .application, .asp, .bas, .bat, .cer, .chm, .cla, .class, .cmd, .cnt, .com, .cpl, .crt, .csh, .der, .dll, .docm, .dotm, .exe, .fxp, .gadget, .grp, .hlp, .hpj, .hta, .htm, .html, .inf, .ins, .isp, .its, .jar, .js, .jse, .ksh, .lnk, .mad, .maf, .mag, .mam, .maq, .mar, .mas, .mat, .mau, .mav, .mcf, .mda, .mdb, .mde, .mdt, .mdw, .mdz, .msc, .msh, .msh1, .msh1xml, .msh2, .msh2xml, .mshxml, .msi, .msp, .mst, .ocx, .ops, .osd, .pcd, .pdf, .pif, .pl, .plg, .potm, .ppam, .ppsm, .pptm, .prf, .prg, .ps1, .ps1xml, .ps2, ps2xml, .psc1, .psc2, .pst, .py, .reg, .scf, .scr, .sct, .sfx, .shb, .shs, .sldm, .tmp, .url, .vb, .vbe, .vbp, .vbs, .vsmacros, .vsw, .ws, .wsc, .wsf, .wsh, .xbap, .xlam, .xlsm, .xltm, .xnk
Examples
This sample shows how to upload a file.
using Cobra.WebService.ClientAPI;
using Cobra.WebService.ClientAPI.Client;
using Cobra.WebService.ClientAPI.Application.Files;
.
.
.
CobraServices cobraServices = new CobraServices();
cobraServices.ServiceIdentityData.Username = "SYSADMIN";
cobraServices.ServiceIdentityData.SecurePassword = new SecurePassword();
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('P');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('A');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('S');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('S');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('W');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('O');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('R');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('D');
LoginResult loginResult = cobraServices.Login();
if (!loginResult.Success) {
Console.WriteLine("Login failed.");
return;
}
Console.WriteLine("Login Success.");
ToolOperations toolOperations = cobraServices.CreateServiceOperations<ToolOperations<();
UploadFileServiceArguments uploadFileServiceArguments = toolOperations.CreateToolOperationsServiceArguments<UploadFileServiceArguments<();
uploadFileServiceArguments.PathAndFileName = @"C:\Program Files (x86)\Deltek\Cobra\Samples\Transaction Files\Actuals Transaction File for Demo Month 2 Format 1.csv";
Console.WriteLine("Uploading File...");
UploadFileServiceResult uploadFileResult;
bool hasError = false;
try {
uploadFileResult = toolOperations.UploadFile(uploadFileServiceArguments);
}
catch (System.IO.IOException ex) {
Console.WriteLine("IOException: {0}", ex.Message);
hasError = true;
}
if (!hasError) {
foreach (Cobra.Model.WebService.ServiceMessage serviceMessage in uploadFileResult.GetMessages()) {
Console.WriteLine("Message Type: {0}", serviceMessage.MessageType);
Console.WriteLine("Message: {0}", serviceMessage.Message);
if (serviceMessage.MessageType == Cobra.Model.WebService.MessageType.Error || serviceMessage.MessageType == Cobra.Model.WebService.MessageType.ValidationError) {
hasError = true;
}
}
}
if (!hasError) {
Console.WriteLine("Success: {0}", uploadFileResult.Success);
Console.WriteLine("UploadFileUid: {0}", uploadFileResult.UploadFileUid);
Console.WriteLine("File name: {0}", uploadFileResult.FileName);
Console.WriteLine("Size: {0}", uploadFileResult.Size);
Console.WriteLine("File Hash: {0}", uploadFileResult.FileHash);
Console.WriteLine("Uploading file completed successfully.");
}
else
Console.WriteLine("Uploading file did not completed successfully.");
cobraServices.LogOut();
See Also