[CLOSED] FileUpload (javascript) + WebService

  1. #1

    [CLOSED] FileUpload (javascript) + WebService

    Last edited by Daniil; Jul 06, 2012 at 5:21 PM. Reason: [CLOSED]
  2. #2
    Hi!

    I did it!!! Now, I need send a parameter to WebService... How I do this with form.submit???

    In Javascript, I did:

    form.submit({
                url: '/APP/MZWORDD/MZWORDD.asmx/UploadFileAjax',
                waitMsg: 'Uploading... Please wait...',
                success: function(fp, o) {
    				Ext.Msg.alert('Success', o.result.msg);
    			},
                failure: function(form, action) {
    				switch (action.failureType) {
    					case Ext.form.Action.CLIENT_INVALID:
    						Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
    						break;
    					case Ext.form.Action.CONNECT_FAILURE:
    						Ext.Msg.alert('Failure', 'Ajax communication failed');
    						break;
    					case Ext.form.Action.SERVER_INVALID:
    						Ext.Msg.alert('Failure', action.result.msg);
    				}
    			}
            });
    And the source code of WebService is:

    
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports System.Web.Script.Services
    
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class MZWORDD
        Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        <ScriptMethod()> _
        Public Sub UploadFileAjax()
            Dim request As HttpRequest
            Dim file As HttpPostedFile
            Dim msg As String
    
            request = HttpContext.Current.Request
            file = request.Files(0)
            msg = "File name: " & file.FileName
    
            Dim o As New resultMessage(True, msg)
            Dim serializer = New System.Web.Script.Serialization.JavaScriptSerializer
            Dim context As HttpContext = HttpContext.Current
            Dim response As HttpResponse = HttpContext.Current.Response
    
            response.ContentType = "text/html"
            Dim s As String = serializer.Serialize(o)
            Dim b As Byte() = response.ContentEncoding.GetBytes(s)
            response.AddHeader("Content-Length", b.Length.ToString)
            response.BinaryWrite(b)
    
            Try
                response.Flush()
                response.Close()
            Catch ex As Exception
    
            End Try
    
        End Sub
    
    End Class
    
    Public Class resultMessage
        Private mvarSuccess As Boolean
        Private mvarMessage As String
    
        Property success As Boolean
            Get
                Return mvarSuccess
            End Get
            Set(value As Boolean)
                mvarSuccess = value
            End Set
        End Property
    
        Property message As String
            Get
                Return mvarMessage
            End Get
            Set(value As String)
                mvarMessage = value
            End Set
        End Property
    
        Property msg As String
            Get
                Return mvarMessage
            End Get
            Set(value As String)
                mvarMessage = value
            End Set
        End Property
    
        Sub New(success, msg)
            mvarSuccess = success
            mvarMessage = msg
        End Sub
    
    End Class
  3. #3
    Hi,

    Via "params":
    http://docs.sencha.com/ext-js/4-1/#!...ion-cfg-params

    form.submit({
        params : {
            someParam : 'Hello!'
        }
    })
  4. #4
    Hi!

    After I set de 'params' property, File are not upload...

    Appears that the webservice is invoked to pass the parameter before upload the file...

    any help?
  5. #5
    Oh, sorry, my fail

    I do this!
    If you want, you can close this thread.

    Thanks a lot...
  6. #6
    Quote Originally Posted by supera View Post
    After I set de 'params' property, File are not upload...
    Please provide more details. What exactly does happen? Can you see the file and the extra parameter in the response?

    Is there any errors, exceptions?

    Quote Originally Posted by supera View Post
    Appears that the webservice is invoked to pass the parameter before upload the file...
    I am afraid I have not understood that statement.

Similar Threads

  1. [CLOSED] [MVC] FileUpload in MVC
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 27, 2015, 4:03 PM
  2. [CLOSED] [#92] FileUpload
    By Timothy in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Jan 16, 2013, 3:44 AM
  3. [CLOSED] GridPanel + FileUpload
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 04, 2012, 1:57 PM
  4. [CLOSED] Fileupload reset in javascript
    By sisa in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 10, 2011, 12:23 AM
  5. bug in fileupload
    By pablisho in forum 1.x Help
    Replies: 0
    Last Post: Jul 01, 2009, 10:55 AM

Posting Permissions