on 05-31-2007 1:52 PM
Hi All,
Can any one help me on this, I need some information about File Download & File Upload.
I read tutorial abt file upload and download but some of methods in tutorial are deprecated so i need clear information abt File upload and Download, if possible Code examples.
Thanks
Ragards
Ravi Golla
Hi Ravi,
Create a context attribute and set calculated as true then u will get a getter method,In that u write code like this
IWDInputStream stream = null;
try {
stream = WDResourceFactory.createInputStream(new FileInputStream(new File(<give the location of a file u want to download>));
}
catch (Exception e)
{
e.printStackTrace();
}
return stream;
for open file u set "resource"as Resource type context attribute.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravi
Check out thses links for examples:
/docs/DOC-8661#22 [original link is broken]
Otherwise you can simply follow this code for file download
Use the code like this.
1) Create the button and bind the action for it.
2)then write this code in the action.
3) do not write any thing in the init method.
try {
final byte[] content = this.getByteArrayFromResourcePath("C:
xyz.properties");
final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.UNKNOWN);
try {
final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", false);
window.open();
}
catch(Exception e)
{
wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
}
5) writr the method getByteArrayFromResourcePath
//@@begin others
private byte[] getByteArrayFromResourcePath(String resourcePath)
throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
byte[] part = new byte[10 * 1024];
while ((len = in.read(part)) != -1) {
out.write(part, 0, len);
}
in.close();
return out.toByteArray();
}
//end
Similarly for file upload
Similarly for upload in to server path also do the same
IWDAttributeInfo attInfo =
wdContext.getNodeInfo().getAttribute("upload");
binaryType =
(IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
uploadedName = binaryType.getFileName();
File filename =new File("
<server name>
<folder name>
"+uploadedName ); );
try {
FileOutputStream out = new FileOutputStream(filename);
out.write(b);
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravi,
For uploading use this code
try{
String Upload=wdContext.currentContextElement().getResource().getResourceName();
FileOutputStream fout=new FileOutputStream(new File(upload));
}
catch(Exception e)
{
e.getStackTrace();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ravi,
See <a href="/people/bertram.ganz/blog/2007/05/25/new-web-dynpro-java-tutorials--uploading-and-downloading-files-in-sap-netweaver-70 and Downloading Files in SAP NW 7.0</a> by <a href="https://forums.sdn.sap.com/profile.jspa?userID=585">Bertram Ganz</a>
Valery Silaev
SaM Solutions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
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.