cancel
Showing results for 
Search instead for 
Did you mean: 

how to get data from the File Upload UI element

Former Member
0 Kudos

Hi all

I have created a fileupload UI element and binded it to a resource attribute(dictionary type).

Now I want to retrieve data from the file that i upload.

How to go about it?? any pointers would be helpful...

Regards

Avinash

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos
Former Member
0 Kudos

well thanks ...

Former Member
0 Kudos
Former Member
0 Kudos

Hi,

1. Create an <b>File Upload UI element</b> and bind it with a <b>context attribute</b> say with name <b>up</b> and set the type as <b>Resource (dictionary type)</b>

and use the following <b>code</b>

InputStream text = null;

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);

wdComponentAPI.getMessageManager().reportSuccess("text: "+text);

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

{

op.write(temp);

}

}

op.flush();

op.close();

}

catch(Exception e)

{

e.printStackTrace();

}

Try selecting a <b>.txt</b> file for example

Regards,

Mathan MP

Former Member
0 Kudos

Hi,

You can access the inputstream of the file using the following code:

IWDResource res        = wdContext.getCurrentContextElement()..getFileResource(); //FileResource is the name of the context attribute bound to the Resource property.
InputStream fileStream = res.read(false);

You can now use this input stream to read the contents of the file.

Regards,

Satyajit.