on 06-09-2014 9:06 AM
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
Hi Pavel,
This may be a rights issue. Could you please try to upload your file from your My Documents folder, instead of directly from C:\ ?
Regards,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pavel,
How are the files created? What I mean is, is it possible that the process that creates or downloads the file, is not done yet at the moment that your code tries to upload the file ?
Or is it possible that the file is in use by another process ? Could you test writing a repeater in your code ? In pseudo code:
1. Upload the file
2. On error wait half a second, and then go to 1
In step 2 you could build in a separate check that the file really does exist.
Regards,
Johan
Hi Johan,
Before a trying to upload file to sap i call this function(see below) that check if file exists and she trying to copy file into sap attachment folder , if this function is finished without any exception i call uploadToSap function
private void fileCopyTest(List<string> files)
{
try
{
foreach (string file in files)// try to copy file
{
System.IO.File.Copy(file, filePathInSap + Path.GetFileName(file));
if (!System.IO.File.Exists(filePathInSap + Path.GetFileName(file)))
throw new Exception("File after copy not exist");
}
foreach (string file in files)// delete temp files
{
System.IO.File.Delete(filePathInSap + Path.GetFileName(file));
if (System.IO.File.Exists(filePathInSap + Path.GetFileName(file)))
throw new Exception("File after delete exist");
}
}
catch (Exception Ex)
{
log.writeError("fileCopyTest exeption: " + Ex.Message);
throw;
}
}
User | Count |
---|---|
98 | |
12 | |
10 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.