Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using BST.ExternalDataImport.AttachmentServicer;
- namespace BST.ExternalDataImport
- {
- public sealed class AttachmentUploader
- {
- //WSDL directory: http://10.48.86.222:89/Methods/Attachments.asmx?wsdl
- //Private
- private readonly AttachmentsSoapClient _client;
- private readonly NetworkCredential _credentials;
- //CTOR
- public AttachmentUploader()
- {
- _client = new AttachmentsSoapClient();
- _credentials = new NetworkCredential();
- }
- public async Task AddAttachment(string path, string productCode)
- {
- //Check if exist
- if (!File.Exists(path)) throw new Exception($"File not exist: {path}");
- //Prepare value
- FileInfo info = new FileInfo(path);
- AttachmentModel attachment = new AttachmentModel
- {
- Barcode = productCode,
- Category = "Attachment",
- Extension = info.Extension,
- Name = info.Name,
- NamePl = "Nazwa PL",
- NameCz = "České jméno",
- NameEn = "Name ENG",
- Binary = Convert.ToBase64String(File.ReadAllBytes(path))
- };
- //Send value
- await _client.AddAttachmentAsync(_credentials, attachment, "PL");
- }
- }
- }
Add Comment
Please, Sign In to add comment