Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

File Path Validation

Former Member
0 Likes
883

Hi,

I have to move my data from my program to a flat file on the Application/ Presentation Server. Now i need to validate whether the path provided by user is a valid one or not.

For eg. If the User enter \usr\sap\ in the presentation server path. The file shd not be saved there instead the user shd get a message to give the correct file path.

And in case of Application Server if the user enters c:\temp it shd not accept. Also if the user gives some random value ksdjfhakf.txt in the file path it shd not take.

Please let me know how can we acheive this.

Regards,

FS

4 REPLIES 4
Read only

Former Member
0 Likes
782

Hi,

Use this code in action button for upload a file

InputStream text = null;

int temp = 0;

try

{

File file = new File(wdContext.currentContextElement().getUp().getResourceName());

FileOutputStream op = new FileOutputStream(file);

if(wdContext.currentContextElement().getUp()!=null)

{

text = wdContext.currentContextElement().getUp().read(false);

while((temp=text.read())!=-1)

{

op.write(temp);

}

}

op.flush();

op.close();

String path = file.getAbsolutePath();

wdComponentAPI.getMessageManager().reportSuccess(path);

}

catch(Exception e)

{

e.printStackTrace();

}

Regards,

Jagadish

Read only

Former Member
0 Likes
782

Hi,

Check this link........ here also same discussion.

Read only

Former Member
0 Likes
782

Hi,

Two Options:

1.You can hardcode the file path in your program and check it inside your program .

You can move file path to your filename variable inside your program though the user enters it as input in selection screen.

2. You can create a Ztable with usernames and file paths and then maintain entries and write select queries to validate users and their designated file paths.

Rewards Points if useful.

Anita

Read only

Former Member
0 Likes
782

Hi

Validating file path on the Presentation Server

To validate a file path on the presentation server, use the method directory_exist available in the class cl_gui_frontend_services.

Demo program to validate the file path on the presentation server:

REPORT zdir_test.

TYPE-POOLS: abap.

DATA: v_dir TYPE string.

DATA: v_bol TYPE abap_bool.

v_dir = 'c:\sap\'.

CALL METHOD cl_gui_frontend_services=>directory_exist

EXPORTING

directory = v_dir

RECEIVING

result = v_bol

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.IF NOT v_bol IS INITIAL.

WRITE:/ 'Directory exists.'.

ELSE.

WRITE:/ 'Directory does not exist.'.

ENDIF.

PLZ reward if helpful,

Thanks,

S.Gangi reddy.