Skip to Content
0
Former Member
Jun 09, 2014 at 08:06 AM

Uploading files to SAP via SDK error

161 Views

Hi,

I am using SAP B1 8.8.

I have a error when i trying upload files to SAP via SDK. When i trying to upload file new.pdf i got error message : Source file does not exist , 'C:\old.pdf' . old.pdf this file that i was added before.

This a code that i am using for uploading file :

public string uploadToSap(string file, int docEntry,string tablename)

{

string error = null;

try

{

SAPbobsCOM.Attachments2 att;

SAPbobsCOM.Recordset RS;

if (oCompany.Connected == false)

oCompany.Connect();

att = (SAPbobsCOM.Attachments2)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);

RS = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

RS.DoQuery("select [AtcEntry] from " + tablename + " where [DocEntry] = '" + docEntry + "'");

int key = Convert.ToInt32(RS.Fields.Item(0).Value);

if (key != 0)

{

if (att.GetByKey(key) == false)//getting Attachments2 object condition

{

throw new Exception("can't upload file (cant't get by key Attachments2 object)");

}

att.Lines.Add();

}

att.Lines.FileExtension = Path.GetExtension( file).Replace(".", "");

att.Lines.FileName = Path.GetFileNameWithoutExtension( file);

att.Lines.SourcePath = Path.GetDirectoryName( file);

att.Lines.Override = BoYesNoEnum.tYES;

int err;

if (key != 0)

err = att.Update();

else err = att.Add();

if (err == 0 && key == 0)

{

string mkey = "";

int absoluteEntry;

((ICompany)oCompany).GetNewObjectCode(out mkey);

absoluteEntry = Int32.Parse(mkey);

sapcon.ExNONQuery("UPDATE " + tablename + " SET [AtcEntry] = " + mkey + " WHERE [DocEntry] = '" + docEntry + "'", constr);

}

else if (err != 0)

{

log.writeToLog("Upload to SAP error Adding / Updating Attachemts2 tbl. ");

error = getLastError();

}

}

catch (Exception Ex)

{

log.writeError("Upload to SAP exeption: " + Ex.Message);

throw;

}

return error;

}

Hope for your help.

Thanks