2 Replies Latest reply on Aug 3, 2010 4:02 AM by mfriasv

    Upload file to SQL Server from Flex




      from my Flex app I want users to upload a .csv file to SQL server.I thought a possible approach would be:


      -upload file to the server

      -check the file there

      -send back the file to flex to sow it in a datagrid


      I am stuck in the uploading. I have the following code but I am always getting the 2038 i/o error. There is even no request to the server according to Httpfox. Any ideas will be appreciated.




      <mx:Canvas width="100%" height="100%" backgroundColor="#91A7B2">
                      import mx.managers.PopUpManager;
                      import mx.controls.Alert;
                      private var fileRef:FileReference = new FileReference();
                      private var fileSelected:Boolean = false;
                      private var statusFile:String = "Select file";
                      private var urlReq:URLRequest = new URLRequest();


                      private function onCreationComplete():void
                          fileRef = new FileReference();
                          fileRef.addEventListener(Event.SELECT, onFileSelected);
                          fileRef.addEventListener(Event.COMPLETE, onUploadComplete);
                          fileRef.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
                          fileRef.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);
                          fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadError);
                      private function closeMe():void
                      private function selectFile(evt:MouseEvent):void
                      private function onFileSelected(evt:Event):void
                          fileSelected = true;
                          fileInput.text = fileRef.name;
                          statusFile = "Ready";
                      private function uploadFile(event:MouseEvent):void
                          if (!fileSelected)
                          Alert.show("Select a file!");
                          urlReq.url = "http://myServer/website/CoreSetUploadFile/Default.aspx";
                      private function onUploadProgress(event:ProgressEvent):void
                          statusFile = ((event.bytesLoaded * 100 / event.bytesTotal).toString());
                      private function onUploadComplete(event:DataEvent):void
                          statusFile = "Complete";
                      private function onUploadError(event:Event):void
                          if (event is IOErrorEvent)
                              Alert.show((event as IOErrorEvent).toString());
                          else if (event is SecurityErrorEvent)
                              Alert.show((event as SecurityErrorEvent).toString());


              <mx:VBox x="52" y="70">
                      <mx:Button label="Browse" click="selectFile(event)"/>
                      <mx:TextInput id="fileInput" editable="false" width="200"/>
                  <mx:Button label="Upload file" click="uploadFile(event)" enabled="{fileSelected}"/>
                      <mx:Text text="Status: "/>
                      <mx:Text text="{statusFile}"/>




      ASP.NET code:


         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
              Dim uploadFile As HttpPostedFile = Request.Files("tts")


          End Sub