cancel
Showing results for 
Search instead for 
Did you mean: 

FileDownLoad problem....

david_fryda2
Participant
0 Kudos

Hi everyone,

I am trying to save a file into my hard disc.

Here is the code.

public void onActionButton(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionButton(ServerEvent)

try {

final byte[] data = "Hello, World!".getBytes("UTF-8");

final IWDAttributeInfo fileAttrInfo = wdContext

.nodeRoot()

.getNodeInfo()

.getAttribute("FileDownLoad");

final IWDModifiableBinaryType pdfType =

(IWDModifiableBinaryType)

fileAttrInfo

.getModifiableSimpleType();

/* In addition the FileDownload

  • UI element needs for defined resource types

*/

IRootNode nodeRoot = wdContext.nodeRoot();

IRootElement elem = nodeRoot.createRootElement();

elem.setFileDownLoad(data);

pdfType.setFileName( "c:
MyPdfFile.pdf" );

pdfType.setMimeType( WDWebResourceType.PDF );

wdContext.currentContextElement().setText("Finish!");

} catch(Exception e) {

wdContext.currentContextElement().setText("Error!" + e);

}

//@@end

}

For some obscure reasons, I do not see the file...

Can someone help.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

You are not able to see the file because the component is deployed and run on the server. You are trying to give a local path. Check this post. It talks about how to write to a XML file and then read the XML file. In you case its going to be a PDF file.

Hope that helps.

regards

ravi

david_fryda2
Participant
0 Kudos

Thanks Ravi for the answers.

Regards.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi David,

You are downloading a .txt file .Y are u saving it as a pdf file. If that is the requirement we cant do it directly by changing the name alone.

The filetype should be same. You can just set the file type.

Wat is the status now. Is it asking for a open or save option when u click the UI element??

Regards

Bharathwaj

Former Member
0 Kudos

hi David,

Sorry..just browsed the code..

final byte[] data = "Hello, World!".getBytes("UTF-8");

what does this mean.. ?

We have to get the file bytes using a file stream object .And set it for the download element.

say ..

File file= new File("c:
demo_files
");

byte b[]=new byte[(int)file.length()];

FileInputStream inp = new FileInputStream(file);

inp.read(b);

wdContext.currentRootElement().setDownload(b);

Otherwise the byte data wil not be available for the element..

Is the file download link disabled..?

Regards

bharathwaj

Message was edited by: Bharathwaj R

Message was edited by: Bharathwaj R

david_fryda2
Participant
0 Kudos

Thanks.

Here is what I wroted :

File file= new File("c:
demo_files.txt");

byte b[]=new byte[(int)file.length()];

FileInputStream inp = new FileInputStream(file);

inp.read(b);

wdContext.currentRootElement().setFileDownLoad(b);

pdfType.setFileName( "c:
MyPdfFile.pdf" );

pdfType.setMimeType( WDWebResourceType.PDF );

So in fact, I am reading from a demo_files.txt and downloading the content in a PDF file.

I add in the the "text" attribut a simple text which is underlined when I run the WebDynPro.

Do I have to write there a text ?

The File|DownLoad UI is enabled by the way.

Thanks.

Former Member
0 Kudos

Hi David,

Is ur server ur local machine. When u upload a file it will be uploaded in the server . Check if its in c drive of the server.

If u have checked it please print the exception ..

I think u have set it in a attribute.. did u check that..check if its having any error.

Check this and do post if there is any other problem

Regards

Bharathwaj

david_fryda2
Participant
0 Kudos

Hi Bharathwaj,

Thank u for the help.

My server is not on my local machine.

I do not get any exception.

Notice that I am trying to do a FileDownload...not an upload one.

Thanks.