on 05-17-2005 10:27 AM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.