cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Sourcing: How to get files from folder and set in the document attachments using script.

Former Member
0 Kudos
218

Hi Expert,

I am trying to fetch files from a folder and want to set it in the agreement's attachment tab.

below are the code which does not work for me. Could you please help on this.

String AgrIDName= doc.getDocumentId();

String dirSep = System.getProperty("file.separator");

String AgrAttachFilePath ="D://FTPFolder//sourcing//ExtractData//Dummy//";

File ma1 = new File(AgrAttachFilePath);

if(!ma1.exists()){ ma1.mkdirs();}

File localPath1 = new File(AgrAttachFilePath +"//"+AgrIDName);

if(!localPath1.exists()){

localPath1.mkdirs();

}

File[] listOfFiles = localPath1.listFiles();

attachments = doc.getAttachments();

ParentObjectReferenceIfc parentRef = TypeFactory.createParentObjectReference(doc);

for(int i=0;i<listOfFiles.length;i++)

{

if(listOfFiles[i].isFile()){

String fileName = listOfFiles[i].getName();

File file = new File(localPath1+"//"+fileName);

FileInputStream fis = new FileInputStream(file);

ByteArrayOutputStream bytes = new ByteArrayOutputStream();

IOUtils.copy(fis, bytes);

attachBean = attachments.create();

settingAttach= attachBean.getAttachment().setFileData("CCW_v6.01.xls",fis,parentRef,session);

attachBean.setAttachment(settingAttach);

//FileOutputStream fos = new FileOutputStream(file);

//fos.write(bytes.toByteArray());

//fos.flush();

//fos.close();

bytes.close();

fis.close();

}

}

Accepted Solutions (0)

Answers (0)