cancel
Showing results for 
Search instead for 
Did you mean: 

file open using Webdynpro for java

Former Member
0 Kudos

Hi,

I have a file "SAP.JPEG" in remote machine location "
SAP\NetWeaver\WebDynpro".

In my webdynpro application...I have a button and the action "OpenFile"...

My question is on click of the button, how can I open the file "SAP.JPEG".

Please advice me how to proceed with this.

Rgds,

Patana

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Well you'll get some answers in below thread:

Don't think remote location is possible as such but the thread has answers on opening file from local path..Hope it helps.

Former Member
0 Kudos

Hi...Any other solution?

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

it is possible to access the file from the remote system using webdynpro java. your requirements is quite possible.

the prerequisites are:

the SAP WebAS Server and the remote system are in the same network, and the folder (in your case "SAP") is shared folder with access permissions.

let us assume your remote system name is remSys09.

add an ui element image in the layout. and create an attribute named "image " bind it to the property source

use this below code to show the image.

try {

File f =new File("////remSys09//SAP//NetWeaver//WebDynpro//SAP.JPEG");

BufferedInputStream bis= new BufferedInputStream(new FileInputStream(f));

byte[] image = new byte[bis.available()];

bis.read(image);

IWDWebResource webResource = WDWebResource.getWebResource(

image,

WDWebResourceType.JPG_IMAGE);

wdContext.currentContextElement().setImage(webResource.getURL());

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Regards,

Naga

Former Member
0 Kudos

Hi Naga...thanks for your response.

I feel this is a right approach...and i have few questions here. I AM STILL TRYING TO OPEN THE FILE..

As you have explained here...

"add an ui element image in the layout. and create an attribute named "image " bind it to the property source"

....Is that UI element image is required? If required...its source property requires a string type. So what to do for this?

I have created an atribute "image" and bind it to the type com.sap.ide.webdynpro.uielementdefinitions.Resource.

And I have created a button and an action "OpenFile"

Inside the method OnActionOpenFile i have written the code that u have suggested.

And what is this below line implies....

byte[] image = new bytehttp://bis.available();

I am still not able to open the file.

Pl advice.

Regards!

Former Member
0 Kudos

Hi,

the attribute image type is string and bind it to the source property of UI element IMAGE.

Actual line of code.

below line implies....

byte[] image = new byte[bis.available()];

Regards,

Naga

Former Member
0 Kudos

Hi Naga....thanks for your response!

When I run the application....the UI is not rendering the file (image) OR throwing any errors.

Former Member
0 Kudos

Hi,

post the exception details and stack trace.

Regards,

Naga

Former Member
0 Kudos

Hi All,

Here is very simple method to open file/image from the remote location or from your local system.

Its required to encode only the file name if it has got special character.

Here my file name is {E3E1215E-038B-4279-9B7D-13A2416D7CE6}_Sunset.jpg

And the path is //Server_name/X/ABCD/XYZ/2008/01/16843/

public void onActionOpenAttachment(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionOpenAttachment(ServerEvent)

String strFilePath = java.net.URLEncoder.encode("{E3E1215E-038B-4279-9B7D-13A2416D7CE6}_Sunset.jpg" );

strFilePath = "File://Server_name/X/ABCD/XYZ/2008/01/16843/" + strFilePath ;

wdContext.currentContextElement().setAttachment(strFilePath );

String title="Attachment";

String strPath = wdContext.currentContextElement().getAttachment() ;

IWDWindow win=wdComponentAPI.getWindowManager().createNonModalExternalWindow(strPath,title );

win.show();

//@@end

}

Regards,

Patana

Former Member
0 Kudos

WebDynpro doesn't support Client side scripting. Hence you can not access files from remote machines.

You can do.

1] Upload file from local machine to server (You can even keep it in context attribute of type Resource)

2] on show button action; open the it in external window - hint: use resource.getUrl().

regards

vinod.

NarendraChandel
Contributor
0 Kudos

Hi,

Yes you can open a file from your local machine but can't open from a remote m/c.

For opening a file from your local m/c you can use File Upload UI element.

Regards

Narendra

Former Member
0 Kudos

Hi Narendra...that was helpful!

I would like to post this as NOT YET ANSWERED..I am looking for some more advices regarding subject mentioned above.

Thanks!

Former Member
0 Kudos

Hi Patana,

WDP will not be aware of a file in a local machine unless you create a link between then (browser - server).

You need to use a stream to do that, in WDP case, it would be the FileUpload. Once you have the file in memory (or in disk case you have already write a file from the stream) you can open it using any method that is available in Java.

Trying to achieve something similiar in an Automated way where you, as server, can 'Query' for any file in the client, leads to security problems. (IE, you could get any file from the user's machine without asking for permission) - To do something like that, you will need to use something like Java WebStart, in that case, you would build an application that the client downloads and accept giving the application control or permission to the local machine.

I don't think this is possible, not the way you imagine it would be. I've never did an upload component in WDP, but as far as I know HTML, it shouldn't be possible 'change' whatever the user selected in that (once again, we would have security problems).

I hope somehow this help you, maybe you need to change your approach to your problem in order solve it.

Regards,

Daniel

NarendraChandel
Contributor
0 Kudos

Hi Patana,

There is no way you can open a file stored in a remote machine using webdynpro application.

The one way i know is that the file should be stored in the server m/c and then you can use File Download UI elmensts to open that file.

if you want more information on the above approach i can help you out.

Regards

Narendra

Former Member
0 Kudos

Hi Narendra...thanks for your response!

Please see below link..

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/607e9392-8167-2b10-b9a8-e0aa297e...

It is true that we are able to create the folder in the local director. If that is the case, why it is not possible to open the file?...can we open the files at least from the local machine (..thats is from any local drive) ! IF it is not possible...then it must be a bug right!

Rgds,

Umapathi

Former Member
0 Kudos

I think you should be having the file on the server for it to work... May be if I find something, I'll post back.

Former Member
0 Kudos

Hi

SAP.JPEG should be placed in Mime folder of your DC.After that create two attributes one for alt other for source Properties(image UI Element) and bind to the image element.Create one action in that write code like get the attribute of image and set it in approriate <attribute>.

yogesh_galphade
Contributor
0 Kudos

Hi

Try using the code of pdf file opening by changing the content type.