public int AttachFile(string pStrFile) { int lIntAttEntry = -1; SAPbobsCOM.Attachments2 lObjAttachment = (SAPbobsCOM.Attachments2)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2); try { string lStrFileName = pStrFile; lObjAttachment.Lines.Add(); lObjAttachment.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(lStrFileName); lObjAttachment.Lines.FileExtension = System.IO.Path.GetExtension(lStrFileName).Substring(1); lObjAttachment.Lines.SourcePath = System.IO.Path.GetDirectoryName(lStrFileName); lObjAttachment.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES; if (lObjAttachment.Add() == 0) { lIntAttEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); } else { LogService.WriteError(string.Format("[AttachmentDI - AttachFile] {0}", DIApplication.Company.GetLastErrorDescription())); throw new Exception(DIApplication.Company.GetLastErrorDescription()); } } catch (Exception ex) { LogService.WriteError(string.Format("[AttachmentDI - AttachFile] {0}", ex.Message)); LogService.WriteError(ex); throw new Exception(string.Format("Error al guardar el archivo adjunto {0}: {1}", pStrFile, ex.Message)); } finally { MemoryUtility.ReleaseComObject(lObjAttachment); } return(lIntAttEntry); }
public int AttachFile(string pStrFile) { int lIntAttEntry = -1; SAPbobsCOM.Attachments2 lObjAttachment = (SAPbobsCOM.Attachments2)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2); try { string lStrFileName = pStrFile; lObjAttachment.Lines.Add(); lObjAttachment.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(lStrFileName); lObjAttachment.Lines.FileExtension = System.IO.Path.GetExtension(lStrFileName).Substring(1); lObjAttachment.Lines.SourcePath = System.IO.Path.GetDirectoryName(lStrFileName); lObjAttachment.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES; if (lObjAttachment.Add() == 0) { lIntAttEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); } else { UIApplication.ShowMessageBox(DIApplication.Company.GetLastErrorDescription()); LogService.WriteError("AttachmentDI (AttachFile) " + DIApplication.Company.GetLastErrorDescription()); } } catch (Exception ex) { UIApplication.ShowMessage(ex.Message); LogService.WriteError("AttachmentDI (AttachFile) " + ex.Message); LogService.WriteError(ex); } finally { MemoryUtility.ReleaseComObject(lObjAttachment); } return(lIntAttEntry); }