on 08-18-2005 1:29 PM
Hi
Does anybody know if there's any documentation on upload/download applications.
i saw a general UI tutorial but it explained only how to design the iView and didn't explain the code behind.
Hi
A brief but apt description on using FileDownload UI element is given below.
Insert the File Download UI element into the View.
The File Download UI element has various properties out of which only the data property is bindable and mandatory.
Bind this property to a context attribute of type binary.(Lets call the attribute filedata)
The file to be downloaded will be stored in this attribute.
The File Download element will be active only if there is data in the above attribute.
We have to write the file to be downloaded to the attribute.
Lets now look into the coding part how this can be achieved.
Consider that you have created a value attribute filedata of type binary in the context of the view. Also consider that the name of the file in server is test.doc.At this moment the attribute does not have any data.
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);
Kindly revert back if you find this useful. I can help you with the FileUpload functionality too.
Thanks and regards
Leena
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Insert the FileUpload UI element into the View.Besides this, a button is also inserted in whose action we write the code for uploading (copying to server) data. Next, create a node, and within it, create two value attributes for binding to the data(of type 'binary') and filename(of 'string' type) properties of the FileUpload UIElement.
An action is created for the button. It is inside the method for this action that we will be writing the code for creating a file in the destination (server) and copying the contents from the source (where the file lies) to the file created in the server. This action is then bound to the onAction property of the button.
In wdDoInit, create an element of the node and bind it to the node. After doing that, write the following code
IWDAttributeInfo attInfo = wdContext.node<<Node name>>().getNodeInfo().getAttribute("<<attribute bound to 'data' property>>");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;
In the onAction method for the button, specify the location where you want the file to be uploaded. On browsing, you get the file name in the value attribute assigned to the filename property of FileUpload. Create a file by this name in the sever. The contents of the file is present in the value attribute bound to 'data' property in the form of binary data. This is written to the file created. This happens when you click the button. The code for this is given below.
try
{
String location = "<<location to where the file has to be uploaded>>"; //for eg: if you give it as 'C://', then the file is uploaded to the C drive of the server.
String file = wdContext.current<<Node>>Element().get<<attribute bound to 'filename' property>>();
String fileName = location +file;
File dest_file = new File(fileName);
FileOutputStream out = new FileOutputStream(dest_file);
if(element.get<<attribute bound to 'data' property>>() != null)
out.write(element.get<<attribute bound to 'data' property>>());
else
wdComponentAPI.getMessageManager().reportSuccess("The data is null");
out.close();
}
catch (FileNotFoundException e)
{
wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());
}
catch (IOException e)
{
wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());
}
Kindly reward points for the posts if you find them useful.
Thanks and regards
Leena
Hi Leena,
Thanks for your help. my problem is almost solved because of your your help.
However, when adding a "File upload element" it comes with an input field and a "browse button" i would like to put a breakopoint on the browse button( when pressing the browse button) but don't find in the code any action for clicking the browse button.
i ask you this because when i run the application through my IDE (eclipse) the application runs great and the file is uploaded to the destnation, however when i deploy on a Portal (Netweaver 2004s) the application doesnt work properly, after browsing through the files an clicking the upload button the application falls.
hope you can help me in that as well, and if not thank you very much for all your help up to now.
Matan
Hi,
check this link
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/web dynpro sample applications and tutorials.htm
These tutorials will help for file upload and dowbnload
Regards,
RK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
refer this link.it may be useful to u.
http://help.sap.com/saphelp_erp2004/helpdata/en/5a/90ff4cd0c8cd48a69b836e5e550880/frameset.htm
rdgs,
G
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.