on 06-09-2010 2:30 PM
Hi,
I am pretty new to this topic and need some help.
I need a Web Dynpro App where I can select a file via FileUpload UI Element and save this file to a predefined path e.g. to a server. I already found [this help|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71?quicklink=index&overridelayout=true] but in this example the file is stored at the SAP Server!
How can I achieve this? May you give me a sample code?
I appreciate your help.
Regards
Hi Martni,
If you are trying to store a file into a folder in WAS(Web Application Server) here is the code snippet. It worked for me, so you can try it and let me know if it works for you or not.
try{
File fp = new File(relativePath+ fileName);
fp.createNewFile();
FileOutputStream fos = new FileOutputStream(fp);
BufferedOutputStream bos = new BufferedOutputStream(fos);
InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false);
int l_int_NoOfBytes = l_is_FileStream.available();
byte[] byteArray = new byte[l_int_NoOfBytes];
l_is_FileStream.read(byteArray, 0, l_int_NoOfBytes);
bos.write(byteArray);
bos.flush();
}
catch (Exception e) {
wdComponentAPI.getMessageManager().reportException("Cannot save the file: "+fileName);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martni, Above answer was incomplete
try{
File fp = new File(relativePath+ fileName);
fp.createNewFile();
FileOutputStream fos = new FileOutputStream(fp);
BufferedOutputStream bos = new BufferedOutputStream(fos);
InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false);
int l_int_NoOfBytes = l_is_FileStream.available();
byte[] byteArray = new byte[l_int_NoOfBytes];
l_is_FileStream.read(byteArray, 0, l_int_NoOfBytes);
bos.write(byteArray);
bos.flush();
}
catch (Exception e) {
wdComponentAPI.getMessageManager().reportException("Cannot save the file: "+fileName);
}
In the above snippet "relativePath" is the path to the folder in WAS and "filename" is the name of the file along with its extn Ex. test.doc, or image.jpg
InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false)
The above line of code is the sixth line in the snippet and here "elAttachmentsElement" is the element of the node having "Va_Resource" context attribute, which is bound to FileUpload UI element.
Regards,
Vishweshwara P.K.M
Edited by: Vishweshwara P.K.M on Jun 28, 2010 1:31 PM
Hi Visweswarayya,
I am also doing the same upload file.but I want to save the file in one of my drive path .
for example I want to save the file in " D " drive of my mechine.I have given the path as " D:\XYZ folder name.but the the colun : is not getting accepted after the drive name.
as far as I know the path should be D:\XYZ folder name.
is the path should be given in any other way apart from this?
appriciate your help.
Raji
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
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.