cancel
Showing results for 
Search instead for 
Did you mean: 

FileDownload and FileUpload in Webdynpro nw04

Former Member
0 Kudos

Hi everybody,

Can you please tell me how to use FileDownload and FileUpload functionality in Webdynpro. we want to Upload a file in a folder in server from local machine and once file is Uploaded then it should be available for downloading.

I am working on NW04 not on NW04s so please tell me according to that.

thanks & regards....

Gaurav Makin

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Solved

former_member720137
Active Participant
0 Kudos

Hi

First of all there is no Resource property in NW04 FileUpload UI element. Resource property is in NW04s. So u have to use a context of binary type and bind it to data property of FileUpload UI element.

Refer this doc further it will help u..

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f">Upload and Download in NW04</a>

Regards

Puneet

Message was edited by:

Armin Reichert

Former Member
0 Kudos

Hi Makin,

For file down load u have to use a UI element as "File download".

u just create context attribute as setdownload_res and file data.

setdownload_res as of type "com.sap.ide.webdynpro.uielementdefinitions.Resource" then bound it to the ui element "resource".

file data as of type "com.sap.tc.webdynpro.progmodel.api.IWDInputStream"

and set calcuclated as true and read only as true.

then in doinit method u just write this code

IWDAttributePointer attr = wdContext.currentContextElement().getAttributePointer("fileData");
IWDResource res = WDResourceFactory.createResource(attr,null,WDWebResourceType.UNKNOWN);
wdContext.currentContextElement().setDownload_res(res);
wdComponentAPI.getMessageManager().reportSuccess(""+c); 


after this in the getter method u write this code
IWDInputStream stream = null;
try
{
stream = WDResourceFactory.createInputStream(new FileInputStream(new File("<pathof the file to be download>")));

}
catch(Exception e)
{
e.printStackTrace();
}
return stream
  

Former Member
0 Kudos

Hi Makin,

Use this code in action button for upload a file

Here up is a context attribute of type "com.sap.ide.webdynpro.uielementdefinitions.Resource"

It is to be bind with upload UI element property called "resource"

InputStream text = null;
int temp = 0;
try
{
File file = new File(wdContext.currentContextElement().getUp().getResourceName());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getUp()!=null)
{
text = wdContext.currentContextElement().getUp().read(false);
while((temp=text.read())!=-1)
{
op.write(temp);

}

}
op.flush();
op.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
}
catch(Exception e)
{
e.printStackTrace(); 
}

former_member186016
Active Contributor
0 Kudos

Hi Gaurav,

See this:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94a...

Answers everything about uplaoding and downloading files in web dynpro.

There is a section for 04 also in the link.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081...

Regards,

Ashwani Kr Sharma

Former Member
0 Kudos

Hi Ashwini,

Thanks for your reply but there is one thing i want to know that after uploading the file where we can find that file i.e. where it is saved.

Can we save it in our own folder on the server.

And also tell me how to Download the same file which is being Uploaded.

thanks & regards...

Gaurav