0 Replies Latest reply on Jul 16, 2009 2:48 PM by anu3000

    download to CSV file using FLEX

    anu3000 Level 1

      Hi,

      I have download to CSV working fine, but i need the filename along with extension "CSV" when filereference object opens in browser,

      though i included CSV in the filename flex is ignoring it..

      Can anybody let me know how i can accomplish what i am looking for ?

      Thank You...Anu

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      import sample.DataGridDataExporter;
      import flash.net.FileReference;
      import flash.net.URLRequest;
      import flash.net.URLVariables;
      import flash.net.URLRequestMethod;
      import mx.controls.Alert;
      private static const CSV_DOWNLOAD_END_POINT:String = "http://q0571478:9081/CsvFile/servlet/GetCSV";
      private var downloadFileRef:FileReference = null;

      private function exportCSV ():void
      {
      var csvData:String = DataGridDataExporter.exportCSV (dg);
      console.text = csvData;
      if (csvData.length > 0)
      {
      downloadCSV (csvData);
      }
      }
      private function downloadCSV (csvData:String):void
      {
      if (!downloadFileRef)
      {
      downloadFileRef = new FileReference();
      }
      var request:URLRequest = new URLRequest();
      var fileName:String;
      fileName = "ccdownload.csv";
      request.url = CSV_DOWNLOAD_END_POINT;
      request.method = URLRequestMethod.POST;
      request.data = new URLVariables ("csvdata=" + csvData);
      downloadFileRef.download(request, fileName);
      }
      ]]>
      </mx:Script>
      <mx:XMLList id="employees">
      <employee>
      <name>Christina Coenraets</name>
      <phone>555-219-2270</phone>
      <email>ccoenraets@fictitious.com</email>
      <active>true</active>
      </employee>
      <employee>
      <name>Joanne Wall</name>
      <phone>555-219-2012</phone>
      <email>jwall@fictitious.com</email>
      <active>true</active>
      </employee>
      <employee>
      <name>Maurice Smith</name>
      <phone>555-219-2012</phone>
      <email>maurice@fictitious.com</email>
      <active>false</active>
      </employee>
      <employee>
      <name>Mary Jones</name>
      <phone>555-219-2000</phone>
      <email>mjones@fictitious.com</email>
      <active>true</active>
      </employee>
      </mx:XMLList>
      <mx:Panel title="DataGrid Control Example" height="100%" width="100%"
      paddingTop="10" paddingLeft="10" paddingRight="10">
      <mx:Label width="100%" color="blue"
      text="Select a row in the DataGrid control."/>
      <mx:AdvancedDataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{employees}">
      <mx:groupedColumns>
        <mx:AdvancedDataGridColumn dataField="name" headerText="Name"/>
        <mx:AdvancedDataGridColumn dataField="phone" headerText="Phone"/>
        <mx:AdvancedDataGridColumn dataField="email" headerText="Email"/>
      </mx:groupedColumns>
      </mx:AdvancedDataGrid>
      <mx:Button label="Export CSV" click="exportCSV ()"/>
      <mx:TextArea id="console" width="100%" height="100%" />
      </mx:Panel>
      </mx:Application>