cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a File in a Web Dynpro App

Former Member
0 Kudos

Hi,

I hava an application and I need to create a simple file, this file should have a name ("USER_001_"sequence".lst") This file is needed to be sent by mail. What do you suggest is the best way to achive this?.

I tryed to get some info about creating files in a Web Dynpro App but nothing found yet.

Thanks.

RR.-

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI Ramien,

You would be able to create the file only on the server and that you can do using the normal java code :

File MyFile = new File(fileName); <i>// fileName should

have the absolute path as well like "C://ABC/USER_001_"sequence".lst") </i>

FileOutputStream out = new FileOutputStream(MyFile);

out.write(<data to be written in bytes>);

<i>// If you have string 'str' you can convert it into corresponding bytes by str.getBytes()</i>

out.close();

Hope this helps,

Best Regards,

Nibu.

Answers (1)

Answers (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Ramien,

beneath Nibu's hint how to create file, once you have it created you can use - again - standard java mail functionality to add such a file as attachement (for example providing the file's InputStream as argument for a MimeBodyPart, to be used as one BodyPart in a MimeMultipart). See http://java.sun.com/products/javamail/javadocs/index.html

Anyhow, the question is where this logic should be implemented, in the WD project or at "backend" (EJB etc), which seems to be more reasonable.

Hope it helps

Detlev

Former Member
0 Kudos

hi,

see this link

/people/sap.user72/blog/2005/06/08/sending-attachments-in-mails

Regards

Rohit

Former Member
0 Kudos

Thank you very much Nibu, Detlev and Rohit.

Yours post are really apreciated, once read that I have one remaining question:

Do I have(must) specify a path to create a file?

If my Was is installed here

C:\usr\sap\J2E\JC00\j2ee\cluster\server0\apps\local\MyApp

if I create a file without scpecifying a path I not supposed it will be created in the root folder of my application?

This is because I'm developing in my local Was installation but, I need to trasmport the app to another Was installed on Unix and how should I deal with paht?

Thanks again,

RR.-

Message was edited by: Ramien Rosillo

detlev_beutner
Active Contributor
0 Kudos

Hi Ramien,

you must specify a path, but this may also be relative, and that means also be empty; for details:

<i>A pathname, whether abstract or in string form, may be either absolute or relative. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.</i>

See http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html for further details.

Hope it helps

Detlev