on 04-12-2011 7:47 AM
Hello,
We have a requirement to built a application where user clicks on a button and a PDF or DOC file opens in a new window.
Now these PDF or DOC files are static and will be given to us by client.
We dont have to create these files, we only need to keep it somewhere in our DC and then deploy them alongwith our application...and then just open it at user wish.
Now the approach in my mind is :
I will keep these files somewhere under src folder in my web dynpro DC.
And then write some code called on click of a button to open these files.
Please commment.
Now the doubt in my mind is :
How will my code recognize...which software to use for opening a particular file.
i.e. if it is a DOC (doc extention) then MS word should be used.
If it is PDF then Adobe acrobat reader should be used.
Will it recognize this automatically ! based of extention of file !!....
Any code related help would be much appreciated.
Thanking you in anticipation.
Hi,
yes you are right. Based on the Resource type it will recognize the automatically by which the doc or PDF should be opened.
webdynpro resource type will decide the type or extension of the file to be opened.
PFB link for the more clarity.
[http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6603] [original link is broken] [original link is broken] [original link is broken];
Regards,
Govindu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thankyou Govindu,
I have used FileDoenload UI element in web dynpro java.
It is working fine for me....
But I have a question...
I have 4 pdf documents and user as per user requirement he wants to see alll 4 links on single page as separate links....
This will be a cakewalk...
but....
I have been following below tutorial :
[SAP HELP|http://help.sap.com/saphelp_nw04/helpdata/en/43/85b311c9af2679e10000000a1553f7/frameset.htm]
In this all binding of PDF document with context element is done under WDdoInit...
So based on this I will have to load all 4 context variables with respective PDF documents....(as wdinit is called once)
even though user wish to read only 1 document.......
So wot if I only wish to populate the required context attribute...
I feel it can only be done if I come to know which link user has clicked....
But in Filedownload UI element case ...this UI elemnt has nothing to do with code in my View Controller.....
How can I catch this event,,,,,,,,,
If I am able to catch the event......I can also give user a button if user wish in place of link....
As in that case I will call the link onAction event of button....!!
Edited by: Saurabh Agarwal on Apr 12, 2011 3:02 PM
hi
The following code uploads a document in server where you deploy the application and also downloads it from there
Hope you are looking for this
you have to make resource type attributes to bind to upload and download UI elements
write the code in action of upload button
File file = new File(".
NUS_DOCs
");
if (!file.exists()) {
file.mkdirs();
}
String OriginalFileName = wdContext.currentUIuploadElement()
.getFILEUPLOAD().getResourceName();
int length = OriginalFileName.lastIndexOf(".");
String fileName = OriginalFileName.substring(0, length - 1);
fileName += new Date().getTime();
fileName += OriginalFileName.substring(length, OriginalFileName
.length());
wdComponentAPI.getMessageManager().reportSuccess(
"saved as : " + fileName);
try {
FileOutputStream out = new FileOutputStream(".
NUS_DOCs
"
+ fileName);
InputStream input = wdContext.currentUIuploadElement()
.getFILEUPLOAD().read(true);
int c = -1;
while ((c = input.read()) != -1) { out.write(c);
}
out.close();
input.close();
wdComponentAPI.getMessageManager().reportSuccess(
"Document Uploaded sucessfully");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//download
File file1 = new File(".
NUS_DOCs
" + fileName);
if (file1.exists()) {
String resourcePath = file1.getAbsolutePath();
IUIdownloadElement documentNodeElement = wdContext
.createAndAddUIdownloadElement();
documentNodeElement.setFILENAME(OriginalFileName);
documentNodeElement.setUrl(resourcePath);
IWDResource resource = null;
try {
wdComponentAPI.getMessageManager().reportSuccess(
"URL generated :" + resourcePath);
resource = WDResourceFactory.createResource(
new FileInputStream(new File(resourcePath)),
OriginalFileName, WDWebResourceType.UNKNOWN, true);
wdComponentAPI.getMessageManager().reportSuccess(
"Resource generated sucessfully");
documentNodeElement.setFILEUPLOAD(resource);
} catch (FileNotFoundException e) {
wdComponentAPI.getMessageManager().reportException(
"FileNotFoundException");
e.printStackTrace();
}
}
best regards
suresh joshi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
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.