cancel
Showing results for 
Search instead for 
Did you mean: 

downloading a file from url

Former Member
0 Kudos

Hi

i have a get a URL for a xml file and i want to download in in client machine so how can i download it.

i have tried the filedownload UI element but it's not working so please tell me what all other options i can try for.

Thanks in advance

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

What means "is not working"?

Armin

Former Member
0 Kudos

i have placed a file download element on the view and bind it to context attribute <b>FileDownLoad</b> and written bellow code in wdDoInit method

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("FileDownLoad");

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

binaryType.setFileName(url);

binaryType.setMimeType(WDWebResourceType.XML);

then when i run the application and click on the download link noting happans no file is downloaded and no error comes

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi nk

The code you typed has been outdated starting since NW 2004s I think. Try to bind property "resource" and property "text" of the control instead of modifying the simple type. Use the following to create the web-resource on runtime

		IWDResource reportResource = WDResourceFactory.createResource(
			binaryFileData,
			fileName, 
			WDWebResourceType.XXX);

BR

Sergei

Former Member
0 Kudos

Hi Sergei

i am not getting. my problem is not about creating web resource actuly i have a string from which that i have converting in IWDCachedWebResource successfully but now i want to download that created file (in web resource)

siarhei_pisarenka3
Active Contributor
0 Kudos

nk

If you have web-resource already try to do the following. Create new attribute in the context of type "com.sap.ide.webdynpro.uielementdefinitions.Resource" and bind property "resource" of your FileDownload control to the attribute. Set the value of the attribute to your real web-resource. In addition, bind property "text" to the name of the file persisted in the context too. This way is better then the way of modyfing simple type you wrote before.

Anyway regarding your code I guess the attribute "FileDownload" is not bound to the FileDownload control. The control has outdated property "data" for this. If the binding is OK maybe you did not put binary data in the attribute "FileDownload" on runtime.

BR

Sergei

Former Member
0 Kudos

hi Sergei

I am totaly confused i will tell you in detail what i have done. please tell me where to modify now.

my file download element don't show property "resource" i bound it to a data property to a attribute of type binary and then written the bellow code in wdDoInit.

String xmlStr ="<?xml version=\"1.0\" encoding=\"utf-8\"?><MT_TEST><Recordset><Row><DT_TEST>aaa</DT_TEST></Row></Recordset></MT_TEST>";

final IWDCachedWebResource resource = WDWebResource.getWebResource(xmlStr.getBytes("UTF-8"),WDWebResourceType.XML);

resource.setResourceName("XML_inline.xml");

resource.setAttachement(false);

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("FileDownLoad");

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

binaryType.setFileName(resource.getAbsoluteURL());

binaryType.setMimeType(WDWebResourceType.XML);

please tell me where i have to modify the code

thanks a lot for your suggetion

siarhei_pisarenka3
Active Contributor
0 Kudos

Hasn't your FileDownload control got property "resource" along with property "data"? It seems you have Webdynpro older than mine. In the case try to modify your code like this

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("FileDownLoad"); 
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
binaryType.setFileName("XML_inline.xml");
binaryType.setMimeType(WDWebResourceType.XML);

wdContext.currentContextElement().setAttributeValue("FileDownLoad", xmlStr.getBytes("UTF-8")); // write binary data to the context

BR

Sergei

Former Member
0 Kudos

Hi,

You must have got cached resource url. Instead of setting in the filename property of Download UI, use LinkToUrl UI element and set its source property to this url.

Regards

Bharathwaj

Former Member
0 Kudos

Hi

that is solved but now i have one more problem like i have a table and on one link i have provided a file download element and the string come in above mention code is returned from a web service and i have to run the web service everytime to generate the string so what can be the best solution. or i have to repeate the same procedure for all the lines.

Former Member
0 Kudos

Hi,

Instead of binding your link attribute to the view, bind it to the Component controller context. Map this attribute to the value node which is the source for your table.

Regards,

Satyajit.

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi nk

There is a method to avoid putting binary data from all the web-services before generation of the table. Binding a web resource to FileDownload control to "resource" property allows to call your web-service to get content of each file directly at time of clicking by the link. I mean the file content would be obtained from the web service when user is clicking the link. Unfortunately it seems your Webdynpro version does not allow to do this because "resource" property is missing.

BR

Sergei