cancel
Showing results for 
Search instead for 
Did you mean: 

File Browser

Former Member
0 Kudos
169

Hi, i'm implementing an action to export the content of a table UI element to an excel file, my problem is that i don't know how to implement a file browser like "save as" action of any microsoft office aplication, for example.

I need help. thx.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Makesure that you are passing the correct value in the following statement

IWDAttributeInfo attinfo1=wdContext.node<value node>().getNodeInfo().getAttribute(<value attribute> );

<Value Attribute> name should be same as in the context(CaseSensitive)

Regards, Anilkumar

Answers (3)

Answers (3)

Former Member
0 Kudos

Ok thx, the file has exported to excel an is saved on server statically, my question is:

with the file download function, can i select a directory where i want to place the file in the client?

thx...

Former Member
0 Kudos

Hi,

Yes you can select the client folder you need to save the file. browse button come along the element. Just create a button and on its action save the file at the position selected by the UI element.

Do send you feedbacks

Regards

Noufal

Former Member
0 Kudos

That was a mistake i just got confused between the download and upload elements.. Download element does not come with a browse button.

Extremely sorry for the wrong information.

Former Member
0 Kudos

Hi,

I worked on a simple scenario on the download element and I feel that it would be helpful for your cause.

I tried downloading a simple file using the download elemnt and it also provides a file browser.

IPrivate<View name>.I<value attribute> ele=wdContext.create<value attribute>();

wdContext.node<value node>().bind(ele);

IWDAttributeInfo attinfo1=wdContext.node<value node>().getNodeInfo().getAttribute(<value attribute> );

ISimpleTypeModifiable type1 = attinfo1.getModifiableSimpleType();

IWDModifiableBinaryType binaryType1=(IWDModifiableBinaryType) type1;

binaryType1=(IWDModifiableBinaryType) attinfo1.getModifiableSimpleType();

binaryType1.setFileName(<file path>);

try{

File f=new File(<filepath>);

int length=(int)f.length();

byte[] b=new byte[length];

FileInputStream input=new FileInputStream(f);

input.read(b);

wdContext.currentDataElement().setDataelement(b);

}catch(Exception e){

wdComponentAPI.getMessageManager().reportException(e.toString(),false);

}

the value attribte has to be in the binary type and bind inside a value node.

bind the attribute to the download element.

On click of the elememnt the browser window opens where you can select the place to save the file.

Regards

Noufal

Former Member
0 Kudos

Hi Noufal, thx for ur help, but it didn't work, i try to prove with ur code example and it launches an ie with an error like follows:

500 Internal Server Error

Application error occurs during processing the request.

Details: java.lang.NullPointerException

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.getClientWindow(ClientManager.java:837)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doExchangeProcessing(DispatcherServlet.java:139)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:95)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doGet(DispatcherServlet.java:35)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

....

I don't know what is happening, i hope u can help me.

Regards.

Former Member
0 Kudos

HI please try this out........Its for upload and downloading also....

First create ur context nodes-- File for uploading and Root for downloading with two value attributes-- 1)Filename of string type and 2)Binary of binary type.

and then see that the Properties(cardinality and Selection) of Nodes File and Root are 1..n else it wil show error.

Create a fileupload UI element and a button for the action of uploading. And a download ui element and in ur init use this code

public void wdDoInit()

{

//@@begin wdDoInit()

element1 = wdContext.createFileElement();

wdContext.nodeFile().bind(element1);

IWDAttributeInfo attInfo = wdContext.nodeFile().getNodeInfo().getAttribute("binary");

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;

binaryType.setFileName("Test.txt");

//here ur uploading functionality is finished but add a //button and add the corresponding code in that

try

{

File input = new File("C:
Test.txt");

int length =(int)input.length();

//Create a byte array b to hold the file

byte b[] = new byte[length];

FileInputStream in = new FileInputStream(input);

//Reading the file to a byte array b

in.read(b);

in.close();

//Setting the data from the byte array to the //context element.

wdContext.currentRootElement().setBinary(b);

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess("Error in File IO"+ex.toString());

}

IWDAttributeInfo attInfo1 = wdContext.nodeRoot().getNodeInfo().getAttribute("binary");

ISimpleTypeModifiable type1 = attInfo1.getModifiableSimpleType();

IWDModifiableBinaryType binaryType1 = (IWDModifiableBinaryType) type1;

}

Add the following code for uploading button

String location = "C:
";

String fileName = location+"Test.txt";

File file = new File(fileName);

FileOutputStream out = new FileOutputStream(file);

if(element1.getUpload() != null)

out.write(element1.getUpload());

else

wdComponentAPI.getMessageManager().reportSuccess("The data is null");

out.close();

}

U CAN add required code in modify view also....... dont forget to handle exceptions wehre ever necessary .

Regards,

Sirisha

Former Member
0 Kudos

Hi Sirisha, thx for ur help, i prove the code that u gave with the difference that the file i'm trying to download is an .xls file, when i execute the download action i have an IO exception, NullPointerException and then the xls file is corrupt, i really don't know what's happening...

I hope u can help me...

regards.

Former Member
0 Kudos

Hello, i obtain a good result!, but the FileDownload Element don't give me a file brwoser to decide where to put the file that i'm downloading, in the client machine...

I hope somebody can help me...

Thx

Regards.

Former Member
0 Kudos

Can you just tell me as to what happens when you click the download element?

Former Member
0 Kudos

HI R u able to Upload that .xls file properly else just check how is that file in server?? and if u want that .xls file to be read in a particular format there is a weblog in sdn to read excel sheet just please go through that.

Tel me if u r able to find that particular .xls file in the server without any corruption?? and when u click on download Ui element after deploying ur application is it opening a new window atleast ?? it will open a new window and show a pop up box asking u to open it or save that file on to ur disk or not... is this at least happening?? let me know ok

Regards,

Sirisha

Former Member
0 Kudos

Hello Sirisha! i only prove the download functionality and now when i click on the download ui element it ask me for save or open the file , the problem is that it saves and downloads the xls file like a txt file and i want to download and save a xls file :$...

I don't know what to do, i hope u can help me...

thx

regards.

Former Member
0 Kudos

Hi Sirisha! i've solved the problem...

THX A LOT!!!!

regards.

Former Member
0 Kudos

Hi,

Please check this.

Regards, Anilkumar

Former Member
0 Kudos

Hi,

When you save a file it i sbeing saved in the server. After that you can download it to the client using the download element which gives the browse functionality.

Might be you can create the file in the server an use the download element and then delete the file present in the server.

Hope that is what your requirement is.

Regards

Noufal

Former Member
0 Kudos

my porblem is how to implement a directory/file chooser from a webdynpro app.

i hope somebody can help me. thx.