cancel
Showing results for 
Search instead for 
Did you mean: 

How to use, download UI element

Former Member
0 Kudos

Hi, i have an excel document in the server, and i want to know how to implement an action for download this file to the client machine.

if somebody can answer with an example code, much better.

thx.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Regards, Anilkumar

Answers (3)

Answers (3)

Former Member
0 Kudos

I hope this code will help you in using file download element.

Create a file download element,it has a property called data bind it to a context variable say "data" of type binary.

Now we have to take the data from the server read it into a byte array and set that to the context variable "data".

//Reading file from server into a byte array "b"

try

{

File output = new File("C:
test.doc"); //"C:
test.doc" is the file in server

int length=(int)output.length();

byte b[] = new byte[length];

FileInputStream in = new FileInputStream(output);

in.read(b);

in.close();

//Setting the data from file to the context variable data

wdContext.currentContextElement().setData(b);

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess("Error in File IO"+ex.toString());

}

//Create the attribute info of the context variable data

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("data");

//using attribute info create a Modifiable binary type

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attinfo.getModifiableSimpleType();

//Set the default file name

binaryType.setFileName("test.doc");

//Explicitly specify the file type , not mandatory

binaryType.setMimeType(WDWebResourceType.DOC);

Do get back for further clarifications.

Hope this helps you.

Regards,

Vijith

Former Member
0 Kudos

Hello Vijith thx a lot, i've tried just like the code that u give abobe, but it doesn't work, when i try to prove it launches a new ie with an exception like:

500 Internal Server Error

Application error occurs during processing the request.

Details: java.lang.NullPointerException

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.getClientWindow(ClientManager.java:837)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doExchangeProcessing(DispatcherServlet.java:139)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:95)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doGet(DispatcherServlet.java:35)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

...

I don't know what is happening, i hope u can help me...

regards.

Former Member
0 Kudos

Hi Joaquin,

Check the following part of code ...

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("<attributename>");

The attribute name should be the same as the one in context.Do check that it should solve your problem.

Regards,

Vijith

Former Member
0 Kudos

Hi Vijith, thx a lot for ur help, i've solved the problem of the download...

Regards.

Former Member
0 Kudos

Hi Silva,

for more details about File download UI and corresponding APIs

follow this link

http://help.sap.com/saphelp_nw04/helpdata/en/c8/32cc6922fb6040a768652aaa0b6879/content.htm

Hope this helped you

Reagrds,

RK

Former Member
0 Kudos

Thx Anilkumar.

As i see in the thread that you suggest me, there are no way to implement a download action easily, or there are?.

Thx.

Former Member
0 Kudos

Create a FileDownload UI element and bind it to a value attribute of type binary.

In the implementation write code to read content in the file to a byte array and set it to the binary Value attribute.

Check this link which has a code snippet.

http://help.sap.com/saphelp_nw04/helpdata/en/d9/376fcad4ba354db3093f147bc3ecd2/frameset.htm

Hope this might be helpful.

Regards,

Sowjanya.

Message was edited by: Sowjanya Chintala

Message was edited by: Sowjanya Chintala