2 Replies Latest reply on Sep 10, 2006 10:58 PM by ParomitaDey15

    Allow users to Download documents from server

    ParomitaDey15
      Hello Everybody,

      I am working on an Flex application where I have to allow the users to Open/Save documents such as Word document, Excel sheet, PDFs, Jpeg, Media files (any digital format document) when a user clicks on a link present in a Flex application. To do this I am using the navigateToURL() method and simply passing the URL string as a URLRequest to the navigateToURL method. This works fine but whenenver the link is invoked and the user selects to Save the Excel sheet or any document it displays an unwanted browser window behind the Open/Save/Cancel dialog box saying action cancelled.

      I can not use "_self" as I require the Flex application to run as is. I tried using the javascript:window.open() but this did not work.

      1) Is there a process to stop the browser window from opening?
      2) How can we invoke a javascript using navigateToURL(), I tried to invoke javascript.alert('Ok') and also javascript:window.open() both did not function.
      3) Is there any other method or flex classes etc. to invoke external applications (allow to download documents from server)?

      Please help me.

      Thanks and Regards,
      Paromita
        • 1. Re: Allow users to Download documents from server
          chris.huston.t10 Level 3
          Paromita,

          You could use the file download functionality. This is from the docs:

          You can let users download files from a server using the FileReference.download() method, which takes two parameters: request and defaultFileName. The first parameter is the URLRequest object that contains the URL of the file to download. The second parameter is optional--it lets you specify a default filename that appears in the download file dialog box. If you omit the second parameter, defaultFileName, the filename from the specified URL is used.

          The following code downloads a file named index.xml from the same directory as the SWF document:

          var request:URLRequest = new URLRequest("index.xml");
          var fileRef:FileReference = new FileReference();
          fileRef.download(request);


          To set the default name to currentnews.xml instead of index.xml, specify the defaultFileName parameter, as the following snippet shows:

          var request:URLRequest = new URLRequest("index.xml");
          var fileToDownload:FileReference = new FileReference();
          fileToDownload.download(request, "currentnews.xml");

          I think this will accomplish what you are trying to do.
          Vygo
          • 2. Re: Allow users to Download documents from server
            ParomitaDey15 Level 1
            Hi

            Thanks a lot for your valuable suggestion, it worked like a champ

            Regards,
            Paromita