cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading with KM

Former Member
0 Kudos

Hello everyone,

I'm trying to download files (of any type) from a KM directory in my webdynpro application.

I allready used the tutorial from SAP, but it consists only on navigating through the KM content.

I have a UI Table that lists all files from a specific directory of KM. It works fine. But now, how can i download it's content?

My example:

private void loadTable(){

	IWDMessageManager manager = wdComponentAPI.getMessageManager();
  	
	wdContext.nodeFiles().invalidate();
  	
	try {
		
	  IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

	  com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
	  
          IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

	  IResourceContext resourceContext = new ResourceContext(ep5User);

	  IResourceFactory resourceFactory = ResourceFactory.getInstance();

	  RID pathRID = RID.getRID("/directory");

	  IResource resource = resourceFactory.getResource(pathRID, resourceContext);

	  ICollection collection = (ICollection) resource;

	  IResourceList resourceList = collection.getChildren();

	  IResourceListIterator resourceListIterator = resourceList.listIterator();

	  while (resourceListIterator.hasNext()) {

		IPrivateFormView.IFilesElement elem = wdContext.createFilesElement();

                tempResource = resourceListIterator.next();

	        elem.setName(tempResource.getName());
	        wdContext.nodeFicheiros().addElement(elem);
	  	  
	  }		
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}

Thanks in advance for any help.

Nuno Santos

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Give a try with this piece of code.


aRid = RID.getRID("/RepositoryName"); 
IResource resource =
resourceFactory.getResource(aRID, resourceContext);
//Get Content
IContent content = resource.getContent();
//Read Content
InputStream IStream = content.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
//out is to store the content of the file from KM
byte[] buffer = new byte[4096];
int bytesread = 0;
while ((bytesread = IStream.read(buffer)) != -1) {
out.write(buffer, 0, bytesread);
}

The above code is an extract from the following link

https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/6615ea90-0201-0010-be81-e7a300fdf212

Hope this is helpful.

Regards,

Santhosh

Former Member
0 Kudos

Thank you, Santhosh, for your help. I read the second tutorial, much more detailed, and solved the problem.

Answers (0)