How to download file in server? - file

I want to download some text file from server, and I found component 'FileDownloader' in Vaadin.
However, I cannot find some examples. All examples are using outputStream.

FileDownloader takes a Resource and there is a subclass FileResource for your case (from the docs):
FileResources are files or directories on local filesystem. The files and directories are served through URI:s to the client terminal and thus must be registered to an URI context before they can be used. The resource is automatically registered to the application when it is created

First of all a FileDownloader needs a FileResource, so you should do something like
FileResource fr = new FileResource(new File("path/to/your/file/on/server"));
FileDownloader fileDownloader = new FileDownloader(fr);
After that you have to associate the FileDownload to a component, like, for example, a button
Button buttonDownload = new Button("Download", FontAwesome.DOWNLOAD);
fileDownloader.extend(buttonDownload);
This basically adds to the component an extension, which is, to keep it simple, a component-independent entity that enables easy comunication between client and server.
When you'll click the button, the extension will activate and will start the download.
Tweak the example to your needs. Cheers.

Related

2sxc: Linking to Permission Locked Resources

We are running into an issue where the link generated by 2sxc when linking to documents that are housed within a protected directory are pointing to an invalid link.
Example:
/Root/Member Resources/Example.pdf
If the Member Resources directory is locked to users with a specific role, the 2sxc document manager folder will correctly map to the resources within file file manager viewer, however the link rendered on page load is linking to Example.pdf where it should link to something like: /LinkClick.aspx?fileticket=8wCAB4arm_8%3d&portalid=0
I tried modifying the Server Resource References setting in the Advanced settings for the field manager (which tells 2sxc to either use a file:0000 value or actual link) and that did not seem to modify the output type/format.
welcome to StackOverflow :)
We at 2sic (the makers of 2sxc) don't often use protected resources, so this may be an oversight on our side, but AFAIK, quite a lot of people use it so it must work.
I believe something like this should actually do the trick (not tested...):
// assuming your item is called Content
// and the file field is called CaseStudy
<a
href="#DotNetNuke.Common.Globals.LinkClick(Content.CaseStudy, Dnn.TabId, Dnn.ModuleId,false)">
download
</a>

Make a hyperlink to a ClearCase file?

In ClearCase, is there anyway to make a straight hyperlink to file? Like of the form
http://mysite/myfile
where all a user has to do is click on the link to view a page or download a file?
We have several non-technical people at our organization who want to look at some of the documentation that developers are storing on ClearCase.
On Windows, you can try and version (add to source control) an xxx.lnk file: a shortcut file, which is set to open an http url.
Once loaded in a snapshot view (or even accessed in a dynamic view), a simple click should open a browser.
An even simpler solution would be to store an xxx.html static page, which would:
open the same browser when double-clicked
list all the actual documentation urls you want.
One file, multiple links!

How to create a file and make it downloadable in GWT?

I want to export the data in a celltable to a CSV file. I understand this must be done in the server side. I'm a bit lost on how to create a file, write the lines and then make the client download it.
One it's served, it could be downloaded automatically or by a "Download" button, is the same.
If you just want to generate file and serve it directly you can create a servlet and hit the servlet url in a Window, You may want to take the same datasource and use it at the server side to convert it into a csv. Please follow along the steps as described in (Download a generated pdf from client) and for downloading that from GWT Window follow (How to download a file via a button click i GWT?),

Silverlight and XtraReports - opening generated PDF report in new tab in browser

I'm trying to send a PDF file from a WCF to silverlight client. PDF is generated by DevExpress XtraReports (in method XtraReport CreateReport(string reportTypeName, RootGenericReportParameterContainer reportInformation)).
Acually PDF is saved somewhere on clients computer after choosing save path in file save dialog - DevExpress takes care of everything - but I don't have a clue how to open the PDF in new tab in browser.
And here is another problem. Silverlight 4 has no access to local file system right? So information about local PDF location is useless. Maybe it would be better to save the PDF in WCF and send a link to it to the client - but how?
I would first question why you need to send the file to the Silverlight client. Get rid of that requirement and the solution becomes much simpler. Silverlight can provide a link that opens a new browser tab. That link would be handled by the web domain, processing it as an HttpHandler, generating the PDF file for the browser. Your PDF url doesn't have to reference a physical file, you can still generate it on request, handle querystring values, etc... Lots of different ways to do this.
Seems that the question isn't really about DevExpress or Silverlight - you're just looking to open a [document of some kind] in a new tab. Each browser natively handles things differently, and users can change tab handling to whatever they want. And (as you mentioned) once the user has downloaded the file, you no longer control it.
Your best bet (and the way I do it) is probably to have a link pointing to a handler/file using "target='_blank' " in the anchor tag on the webpage. From the server side, you would want to set the "Content-Disposition" header to "Inline" to indicate to the browser that the document should be displayed in place instead of downloaded ("Attachment").

Silverlight 4: Read in file from local system without being OOB?

Any tips/tricks on how to read a file from the local system dynamically in silverlight 4 without having to be out of browser?
Impersonation? Toggling app elevated trust on/off programmatically?
Or is this simply impossible to do without being out of browser?
As it stands I have a Pegasus ImageGear PDF viewer that I feed a "LoadDocument" method a stream of a PDF file.
This of course works fine if the file is an application resource and compiled with the application.
StreamResourceInfo resource = Application.GetResourceStream(new Uri("/TestRIA;component/SampleData/test.pdf", UriKind.Relative));
docViewer.LoadDocument(resource.Stream);
This silverlight application will be hosted through a website deployed on a server. This server has a partition specifically for repositories of files. These files in the "D:" partition are currently accessed by an ASPX web application and displayed in a PDF viewer. We're moving to silverlight, so as the user selects the grid row representation of that file in the repository, I know the "NAME" of the file. The repository's location is a string held in the database configured in another application. I simply concatenate the file name to that repository path and have the filepath.
Again, the 3rd party viewer's "LoadDocument" method has two overloads. One that accepts a stream of the PDF and one that accepts the filename of the PDF.
For example I have a click event that feeds the name of the document, and I already have the root path to concatenate it to:
void testButton_Click(object sender, EventArgs e)
{
string docName = myListBox.SelectedItem.Content.ToString();
docViewer.LoadDocument(repositoryPath + docName);
//OR using stream
Stream s = new FileStream(repositoryPath + docName, FileMode.Open);
docViewer.LoadDocument(s);
}
You cannot programatically interact with an arbitrary file in SL4. Period. There's your section of isolated storage you can read from and write to files, but that isn't what you're looking for. You can read and write files through the file open dialog, but again I think that's not what you want.
The only way out of the Silverlight sandbox is the network. You have to have to talk to a non-sandboxed service to do this. SL has OK support for Web Services, Http, and even sockets. This seems doable for you since you're talking about the file being somewhere on a "server".
I remember reading that this will work without elevated trust only if the code is initiated with a user action such as button click.
http://msdn.microsoft.com/en-us/library/ff382752%28v=vs.95%29.aspx
For security purposes, if a Silverlight application is a sandboxed
application, file and print dialog boxes must be user-initiated. This
means you must show them from a user-initiated action, such as the
click event handler for a button.
As a possible workaround, if your Silverlight app is backed by a service, you could make the reading/writing of the file be handled by the service, assuming it has access to the location(s) and sufficient rights in the destination folder(s).
Create an OpenFileDialog box and you can return stream(s) to the selected file(s).

Resources