本文介绍了有谁能帮助我如何在vb2.0中使以下代码可执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ WebHandler Language="VB" Class="Handler" %>

Imports System.Web
Imports System.Web.Script.Serialization
Public Class Handler
    Implements IHttpHandler

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/plain"
        ''"application/json";
        Dim r = New System.Collections.Generic.List(Of ViewDataUploadFilesResult)()
        ''  Dim serializer As New JavaScriptSerializer()
        Dim js As New JavaScriptSerializer()
        For Each file As String In context.Request.Files
            Dim hpf As HttpPostedFile = TryCast(context.Request.Files(file), HttpPostedFile)
            Dim FileName As String = String.Empty
            If HttpContext.Current.Request.Browser.Browser.ToUpper() = "IE" Then
                Dim files As String() = hpf.FileName.Split(New Char() {"\"c})
                FileName = files(files.Length - 1)
            Else
                FileName = hpf.FileName
            End If
            If hpf.ContentLength = 0 Then
                Continue For
            End If
            Dim savedFileName As String = "c:\tmp\" & FileName
            hpf.SaveAs(savedFileName)

            ''Thumbnail_url = savedFileName,
			r.Add(New ViewDataUploadFilesResult() With { _
				Key .Name = FileName, _
				Key .Length = hpf.ContentLength, _
				Key .Type = hpf.ContentType _
			})
			Dim uploadedFiles = New With { _
				Key .files = r.ToArray() _
			}
            Dim jsonObj = js.Serialize(uploadedFiles)
            ''jsonObj.ContentEncoding = System.Text.Encoding.UTF8;
            ''jsonObj.ContentType = "application/json;";
            context.Response.Write(jsonObj.ToString())
        Next
    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

Public Class ViewDataUploadFilesResult
    Public Property Thumbnail_url() As String
        Get
            Return m_Thumbnail_url
        End Get
        Set(ByVal value As String)
            m_Thumbnail_url = Value
        End Set
    End Property
    Private m_Thumbnail_url As String
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = Value
        End Set
    End Property
    Private m_Name As String
    Public Property Length() As Integer
        Get
            Return m_Length
        End Get
        Set(ByVal value As Integer)
            m_Length = Value
        End Set
    End Property
    Private m_Length As Integer
    Public Property Type() As String
        Get
            Return m_Type
        End Get
        Set(ByVal value As String)
            m_Type = Value
        End Set
    End Property
    Private m_Type As String
End Class

推荐答案


这篇关于有谁能帮助我如何在vb2.0中使以下代码可执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:13