on 12-01-2005 5:32 AM
Hi, experts, I have to setup a project to realize pdf downloading with web dynpro. But unluckily, I have tried all the methods in this froum ,there's really strange problem .Because when I click the link of Download UI link, there's no reaction at all, I really don't know why.Below is the codes I used , can anyone help me ? thank you very much!
public void wdDoInit()
{
//@@begin wdDoInit()
IWDAttributeInfo attInfo =
wdContext
.currentContextElement()
.node()
.getNodeInfo()
.getAttribute(
"Pdfsource");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;
binaryType.setFileName("test.pdf");
binaryType.setMimeType(WDWebResourceType.PDF);
try {
int length =
(int) wdContext.currentPdfdownloadElement().getBin_Filesize();
byte b[] = new byte[length];
b = wdContext.currentPdfdownloadElement().getBin_File();
wdContext.currentContextElement().setPdfsource(b);
} catch (Exception ex) {
}
"Pdfsource" is the context value attribute of type binary.And Bin_File is the xstring type parameter from my RFC contains pdf content.
I used two views and one customer-controller . I put some value in the first view to set search condition.and the second then appears and have the download UI element. Are there any additional codes I should use? pls help!
Hi Hao,
Try this out
Suppose the file name is test.doc in c drive in server
create a context attribute filedata of binary type
bind it to data property
write the following code
try
{
File input = new File("C:
test.doc");
int length =(int)input.length();
//Create a byte array b to hold the file
byte b[] = new byte[length];
FileInputStream in = new FileInputStream(input);
//Reading the file to a byte array b
in.read(b);
in.close();
//Setting the data from the byte array to the context element.
wdContext.currentContextElement().setfiledata(b);
}
catch(Exception ex)
{
wdComponentAPI.getMessageManager().reportSuccess("Error in File
IO"+ex.toString());
}
// Structure information of the context attribute
IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("filedata");
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attinfo.getModifiableSimpleType();
// Default File name which appears when opened on client machine
binaryType.setFileName("testing.doc");
//Explicitly setting the file type
binaryType.setMimeType(WDWebResourceType.DOC);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hao,
try this piece of code.......
//@@begin wdDoInit()
IWDAttributeInfo attInfo = wdContext.currentContextElement().node().getNodeInfo().getAttribute("pdfSource");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;
binaryType.setFileName("yourfile.pdf");
binaryType.setMimeType(WDWebResourceType.PDF);
String fileName = "temp
webdynpro
web
local
.......";(file-path)
try
{
File file = new File(fileName);
FileInputStream in = new FileInputStream(file);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte [10 * 1024];
while ((length = in.read(part)) != -1)
{
out.write(part, 0, length);
}
in.close();
wdContext.currentContextElement().setPdfSource_download(out.toByteArray());
}
catch(Exception e)
{
throw new WDRuntimeException(e);
}
//@@end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,Rohit
Thank you for your answer. But my problem is not that, I know how to download, But because now I want to download the Bin_File (xstring type) returned by a RFC,I have tested in R/3, it returns binary as Bin_File, but somehow I can't download by web dynpro, I think maybe it's dynamic download that generate this problem ,But I have tried all the methods in the froum , neither helps. I really got headache with this for 3 days:(
Can anyone check my code ? 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.
By the way, Pdfdownload is my download view's module node, and can I use my code below to get the xstring pdfcontent and set it to the datasource of Download UI?
try {
// int length =
// (int) wdContext.currentPdfdownloadElement().getBin_Filesize();
// byte b[] = new byte[length];
// b = wdContext.currentPdfdownloadElement().getBin_File();
//
// wdContext.currentContextElement().setPdfsource(b);
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.