cancel
Showing results for 
Search instead for 
Did you mean: 

List the files from server

Former Member
0 Kudos

Hi Experts,

I have a requirement in my application, that list out the files from the server in table and also delete the file. Pls specify the code.

Regards,

Kiruba.R

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If you have the source file path (eg: dirpath\filename.txt), then its possible to upload a file without using the FileUpload UI element..

vinod

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Could you be more specific about your requirement.

Regards

PG.

Former Member
0 Kudos

Hi,

In my application, I have uploaded the files to the server. Next I have to display the uploaded files in the table as a linkTo action(e.g some 10 files).When I click the link the files conetent sholud display. After displaying the files, I need to delete the files from server one by one.

Regards,

Kiruba.R

Former Member
0 Kudos

Hi

List all the files from server


 public void listServerFiles( )
  {
    //@@begin listServerFiles()
    wdContext.nodeFiles().invalidate();
    
    IPrivateExperimentView.IFilesElement element;
    
    java.io.File file = new java.io.File( "D:\\Test");
    
    File list[] = file.listFiles();
    for( int i = 0; i < list.length; i++)
    {
    	element = wdContext.createFilesElement();
    		element.setFileName( list[ i].getName());
    	wdContext.nodeFiles().addElement( element);
    }
    
    //@@end
  }

Display the selected file


 public void onActiondownload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActiondownload(ServerEvent)
    IWDResource resource;
    String name = wdContext.currentFilesElement().getFileName();
    String path = "D:\\Test\\" + name;
	InputStream stream;
	try {
		stream = new FileInputStream(path);
		resource = WDResourceFactory.createResource( stream, name, 
						WDWebResourceType.UNKNOWN, true);
		stream.close();
		wdComponentAPI.getWindowManager()
					.createNonModalExternalWindow( resource.getUrl( 0), name).show();
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

Delete the selected file


 public void onActiondeleteFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActiondeleteFile(ServerEvent)
    String path = "D:\\Test\\" + wdContext.currentFilesElement().getFileName();
    
    File file = new File( path);
    file.delete();
    listServerFiles();
    //@@end
  }

vinod

Former Member
0 Kudos

Hi Vinod,

Thanks a lot for your solution. I cant get this line "listServerFiles" from deleted code.

Elaborate it pls.

Regards,

Kiruba.R

Former Member
0 Kudos

Hi,

I think you have tried all the 3 methods in View Controller. The listServerFiles() method lists all the files in the server onces the delete operation is done. You can call this method in init() and in Delete Action..

vinod

Former Member
0 Kudos

Hi Vinod,

Thanks a lot.I have one more doubt.Is it possible to upload the file to server without using the FileUpload UI element.If so pls say how to do it.

Regards

Kiruba.R

nikhil_bose
Active Contributor
0 Kudos

Usually web applications directly accessing client machines file system are restricted due to security concerns.

using a web dynpro, any kind of client file system access possible by File Upload/Download UI elements only.

nikhiL