How to Download a File Just Created

Hi!

I am creating a CSV File using this code:

fstream = new FileWriter(fileLocation);
			BufferedWriter out = new BufferedWriter(fstream);
out.write("TEST");
out.flush();
				out.close();

and I create it in the /tmp directory, how do I make this downloadable from within a Vaadin Portlet? I have found that if I get the Window and look at the methods on it, there is a “open” but it requires a “resource” and not a filepath.

How do I convert my filepath (which points to the newly created CSV file) to a “resource” and then have it downloaded by the User?

Thanks!

window.open(new FileResource(…))
or
window.open(new ExternalResource(…))

might be other Resource implementations too.

Thanks Matthew!

[color=#ed0a0a]

[/color]Hi
I tried the above

public void init() {
final Window mainWindow = new Window(“Jaimatadi Application”);
Label label = new Label(“Hello Vaadin user”);

	mainWindow.addComponent(label);
	final Button downloadResultButton = new Button();
	downloadResultButton.setCaption("Button");
	downloadResultButton.addListener(new ClickListener() {

		public void buttonClick(ClickEvent event) {
			mainWindow.open(new FileResource(new File("C:/test"),
					LogApplication.this));

		}
	});
	mainWindow.addComponent(downloadResultButton);
	setMainWindow(mainWindow);
	
}

but i get this message if i click on the button


Firefox doesn’t know how to open this address, because the protocol (app) isn’t associated with any program.

and in IE 8
One page opens with this url


app://APP/1/test

and IE messages is →

[b]
The webpage cannot be displayed

Most likely cause:
Some content or files on this webpage require a program that you don’t have installed.

What you can try:
Search online for a program you can use to view this web content.

 Retype the address.  

 Go back to the previous page. 

[/b]

Please help me out .

Regards
Neha

You are probably using an old widgetset not compiled for the Vaadin version you are using.
You should recompile or update your widgetset.

Hey,

how can i achieve this:

using Vaadin 7.0.1?

This is a question I would like to have answered too…

However… meanwhile… have you looked at FileDownloader (com.vaadin.server.FileDownloader)

Example:
FileResource fr = new FileResource(new File(“C:/test”));
FileDownloader fd = new FileDownloader(fr);
fd.extend(buttonToClickForDownload); // connect the download action to a button click…

Tanks this works.

Is it possible to check if if the client downloaded the file or if the download is finished.
Because I generate a file which displays the current view or the content of a table (table data is changing while the server is running) on the server.
I’d like to delete it on the server as son as the download is finished.