Skip to Content
avatar image
Former Member

Open PDF or DOC resource


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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 12, 2011 at 08:25 AM


    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(".

    if (!file.exists()) {



    String OriginalFileName = wdContext.currentUIuploadElement()


    int length = OriginalFileName.lastIndexOf(".");

    String fileName = OriginalFileName.substring(0, length - 1);

    fileName += new Date().getTime();

    fileName += OriginalFileName.substring(length, OriginalFileName



    "saved as : " + fileName);

    try {

    FileOutputStream out = new FileOutputStream(".

    + fileName);

    InputStream input = wdContext.currentUIuploadElement()


    int c = -1;

    while ((c = != -1) { out.write(c);





    "Document Uploaded sucessfully");

    } catch (FileNotFoundException e) {


    } catch (IOException e) {




    File file1 = new File(".
    " + fileName);

    if (file1.exists()) {

    String resourcePath = file1.getAbsolutePath();

    IUIdownloadElement documentNodeElement = wdContext




    IWDResource resource = null;

    try {


    "URL generated :" + resourcePath);

    resource = WDResourceFactory.createResource(

    new FileInputStream(new File(resourcePath)),

    OriginalFileName, WDWebResourceType.UNKNOWN, true);


    "Resource generated sucessfully");


    } catch (FileNotFoundException e) {






    best regards

    suresh joshi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12, 2011 at 08:54 AM


    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.

    [] [original link is broken] [original link is broken] [original link is broken];

    [downloading a file from R3 system using webdynpro;



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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...


      I have been following below tutorial :

      [SAP HELP|]

      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