cancel
Showing results for 
Search instead for 
Did you mean: 

File Downloading Fom KM

Former Member
0 Kudos

Hi Frnds,

Can u help me how to Downlod file from KM using NWDS, i'v tryed with Tutorial but its with mime types only i want get it from KM and i need in detail with sample code, i need to do sooner.

please Hope u can help me.

ThanQ

vita.

Accepted Solutions (1)

Accepted Solutions (1)

matteo_fusi2
Participant
0 Kudos

Hi,

try {
	 
		//create an user object from the current user
		IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
		com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser(); 
									
		//create an ep5 user from the retrieved user
		com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
		ResourceContext context = new ResourceContext(ep5User);  
				
		//Give the path to KM in the variable path 
		String path = "<KM_file_path>";  // ex. /documents/test.txt
		RID rid = RID.getRID(path);  

		IResourceFactory factory =  ResourceFactory.getInstance();  
		IResource resource = factory.getResource(rid, context);
		
		IContent content = resource.getContent();
		
		InputStream IStream = content.getInputStream();
		
               ....... 
              ..........

		

	} catch (Exception e) {
		msgMgr.reportException(e.getMessage(),true);				
	}

Regards

Matteo

matteo_fusi2
Participant
0 Kudos

Hi,

if you use a FileDownloadUI Element you can add this code:

.......
               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);
		}
			 
		
		
		IWDResource res =  WDResourceFactory.createResource(out.toByteArray(),
resource.getName(),
WDWebResourceType.getWebResourceTypeForFileExtension(resource.getResourceType()));

		wdContext.currentContextElement().setResource(res); // context attribute bind to FileDownload

Regards

Matteo

Former Member
0 Kudos

Thank Metto,

Thanks for Reply am happy with Ur code but can u explan bit in details b4 writting the code like do i go with ActionLink, Filedownlod or with Button UI, can u explan for me step bu step plz so that i can finesh my task, itrs very kind of u if u can

i hope u do reply soon.

ThanQ

vita.

matteo_fusi2
Participant
0 Kudos

Hi vita,

1. use the FileDownloadUI element and put it in a view

2. bind the property resource of the FileDownloadUI with an attribute of the context of type Resource (Dictionary simple type: com.sap.ide.webdynpro.uielementdefinitions.Resource)

3. before the view is shown on the screen execute the code posted to load the file in the context. For example put the code in wdDoInit() method or in a onPlugIn method of the view.

So the user can download the file

Regards

Matteo

Former Member
0 Kudos

ThanQ For Time Sir,

Its very kind u given for me.

I did as u said every thing is fine now, but when open a File its opeing in Unknow type not in Pdf ro Exesting Format.

i have few Req...nts

1) user need to get Pop Save, Open and Cancel but hear i'm getting only Save and cancel.

2) according my Req.. user get one window with list of KM Files so that he can Click or Get download any of the file wich is in KM.

hope u get it

Plz Reply me Soon .

Thaks Lot

ThanQ,

vita,

matteo_fusi2
Participant
0 Kudos

Hi vita,

take a look to this tutorial

[http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/958fcd90-0201-0010-38aa-d8272da593b6&overridelayout=true]

Regards

Matteo

Edited by: Matteo Fusi on Oct 9, 2009 4:10 PM

Former Member
0 Kudos

Thanks Dear,

With that link i can able to access KM Browser, that is great.

But that is only accessing the DIR's i need to open the file. when am giving the root path according 2 above link as u explaind am able C my all files which is execting in my KM Folder but when i click on it it is not opening through browser can give this small tip plz .

it would be very kind of u Dear.

ThanQ n Regards,

vita.

matteo_fusi2
Participant
0 Kudos

Hi vita,

you can set the property "behaviour" of the FileDownloadUI element

look this link

[http://help.sap.com/saphelp_nw04s/helpdata/en/c8/32cc6922fb6040a768652aaa0b6879/content.htm]

Regards

Matteo

Former Member
0 Kudos

Hi Dear,

I'm getting UnKnown File Type. and Thanks For above link i've gone through that all the link n i made changes also but still i'm getting Unknown File Type.

Plz can U help me out on this ..

ThanQ n Regards,

vitra

Former Member
0 Kudos

Hi Dear,

i have small task but bit draging me... i hope some one can help me out from this.

i am developting one application in wedbynpro with in NWDS with EP7.0 sp14, the devloping application is file Uploding which is am completed but with that file upload i have few parametars(InputFields) need store in KM folder with uploading file,

Like: File Name, File ID, FileDate, File Description like that i have nearly 5 input fields b4 selecting a file from browser user need to enter these input fileds then selcet a file for upload then user can click upload button .

Once user click onbutton the file is uploading sucssessfully in KM @docs/userfolder/ , but problem is am able to upload only file wich is selected through broweser not values which i'v enterd in Inputfield, wht to do get this values in KM plz provide some sample codes.

Plz can u help its very urjent.

ThanQ & Regards,

Vita.

Answers (0)