4 Replies Latest reply on Mar 23, 2010 8:36 AM by GeorgeWS

    downloading files

    GeorgeWS Level 1

      I have a datagrid that displays files that are on my webserver. You can press on the file and download it to the server. Most of my DG that have files work great. The ones that do not are the ones that are trying to diplay only one file. It shows a blank. But if I put a second file in the folder on the server the 2 files show. Has anyone run across this issue?

       

      George

        • 1. Re: downloading files
          Madhav Subedi Level 4

          can you post the code to depict the overall scenario?

          • 2. Re: downloading files
            GeorgeWS Level 1

            Pretty much this is what I am doing. The is an initApp on complete, and the file paths are not real. There is a flashvar SupplierID that changes the folder. Works great except when there is only one file in the folder on the server. When there are 2 or more files it all works perfectly.

             

            <mx:Script>

            <![CDATA[

             

             

            import mx.collections.ArrayCollection;

             

            import mx.rpc.events.ResultEvent;

             

            import mx.controls.Alert;

             

            // Start of Download

             

             

            [

             

            Bindable] public var directoryDS:ArrayCollection;

             

             

            [

            Bindable] public var serviceURL:String;

             

             

            [

            Bindable] public var fileIndex:Number;

             

             

             

             

            public function initApp():void

            public

             

             

            function initApp():

            void

            {

             

            serviceURL =

             

             

            "http://www.youngsmarket.com/myprograms/reviews.cfm?SupplierID="+parentDocument.SupplierID; //Set the URL to the httpservice

            directoryDS =

             

            new ArrayCollection([]); // This is where the results of the httpservice will end up.

            fileIndex = -1;

            directory_srv.send();

             

            // Call the httpservice.

             

             

             

             

             

            // Taking the data returned from the httpservice and creating FileDownload objects to populate the directoryDS array collection.

             

             

            private function setDataSource(evtObj:Object):void

            {

             

             

            var fileDL:DownloadFile;

             

            var collection:ArrayCollection = evtObj.directory.file as ArrayCollection; // pass httpservice result into a local scope

             

             

            var i:int;

             

             

            //loop over results and create a new DownloadFile object and add it to the directoryDS ArrayCollection

             

             

            for (i=0;i < collection.length; i++)

            {

            fileDL =

            new DownloadFile();

            fileDL._file = collection.getItemAt(i).name;

            fileDL._url =

            "http://www.youngsmarket.com/myfiles/"+parentDocument.SupplierID+"/"; // Change this to match your Files directory path.

            fileDL._size = collection.getItemAt(i).size;

            directoryDS.addItem(fileDL);

            }

             

            }

             

             

             

             

             

            // Fire the downloadFile method of the DownloadFile ojbect selected from the Datagrid.

             

             

            private function downloadFile():void

            {

             

             

            // first make sure there is a selection

             

             

            if (fileIndex >= 0)

            {

            directoryDS.getItemAt(fileIndex).downloadFile();

            }

            }

             

             

             

             

             

             

            // labed function for the datagrid size column

             

             

            private function toKiloBytes(item:Object,obj:Object):String{

             

             

            var size:Number = item._size / 1024;

             

             

            if (size >= 1){

             

            return Math.round(size) + " kb";

            }

            else{

             

            return size * 1024 + " b";

            }

            }

             

             

            ]]>

            </mx:Script>

             

            <mx:HTTPService

             

            id="directory_srv" url="{serviceURL}" result="setDataSource(event.result)"/>

             

            <mx:DataGrid

             

            dataProvider="{directoryDS}" id="filesDG" change="setFileIndex(event.target.selectedIndex);"

            width="

            98%" height="98%" themeColor="#73B9B9" doubleClickEnabled="true" itemDoubleClick="downloadFile()">

             

            <mx:columns>

             

            <mx:DataGridColumn dataField="_file" headerText="File" minWidth="150" />

             

            <mx:DataGridColumn dataField="_size" headerText="Size" minWidth="100" />

             

            </mx:columns>

             

            </mx:DataGrid>

             

             

             

            MY CFM  is like this...

             

            <cfoutput>
            <cfset directoryPath="//web/myfiles\#SupplierID#\">
            </cfoutput>
            <cfdirectory action="list"  directory="#directoryPath#"  name="qDirectory">

            <?xml version="1.0" encoding="utf-8"?>
            <directory>
            <cfoutput query="qDirectory">
            <file name="#qDirectory.name#" type="#qDirectory.type#" size="#qDirectory.size#"/>
            </cfoutput>

            </directory>

             

             

            Thanks for looking

             

            George

            • 3. Re: downloading files
              GeorgeWS Level 1

              I still have not found a solution. When displaying files that are on a server in a DG

              if there is only one file in the folder nothing shows in the DG. If there are more than one file it works perfectly.

              Anyone else have this issue?

               

              Thanks

               

              George

              • 4. Re: downloading files
                GeorgeWS Level 1

                Still no solution for this problem.