Avatar of Wayne Barron
Wayne Barron
Flag for United States of America asked on

C# to vb.net conversion code has some errors. Code is for blueimp / jQuery-File-Upload

Hello, All.

I want a better and more professional-looking upload script, and I found this one.
blueimp / jQuery-File-Upload
Demo here, Demo File Upload
Now, I did some checking around, and I found where a guy ported it over to ASP.NET C#, located here (ASP.NET Web Forms – Implementation of BlueImp jQuery File Upload.) So I took the code and converted it from C# to VB.NET using the converter located here, converter.telerik.com.
I installed "Newtonsoft.Json" through "Manage NuGet Packages."
And these are the following errors I am faced with.

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30149   Class 'FileUploadHandler' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'IHttpHandler'.   8_FileUploadHandler.ashx   G:\Inetpub\wwwroot\Website\Photo\WebSite1\Handler.ashx   11   Active

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30149   Class 'FileUploadHandler' must implement 'ReadOnly Property IsReusable As Boolean' for interface 'IHttpHandler'.   8_FileUploadHandler.ashx   G:\Inetpub\wwwroot\Website \Photo\WebSite1\Handler.ashx   11   Active

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30002   Type 'UploadFilesResult' is not defined.   8_FileUploadHandler.ashx   G:\Inetpub\wwwroot\Website \Photo\WebSite1\Handler.ashx   16   Active

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30002   Type 'JsonFiles' is not defined.   8_FileUploadHandler.ashx   G:\Inetpub\wwwroot\Website \Photo\WebSite1\Handler.ashx   28   Active

I also am including a screenshot from VS showing the compiler errors.
Not sure where to go from here with the above-shown errors.

Code for the Generic Handler (Shown in the screenshot above)

<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Web
Imports Newtonsoft.Json

Namespace jFileUploadASP
    Public Class FileUploadHandler
        Implements IHttpHandler

        Public Sub ProcessRequest(ByVal context As HttpContext)
            If context.Request.Files.Count > 0 Then
                Dim file As HttpPostedFile = context.Request.Files(0)
                Dim resultList = New List(Of UploadFilesResult)()
                Dim path As String = context.Server.MapPath("~/Content/uploads/")
                file.SaveAs(path & file.FileName)
                Dim uploadFiles As UploadFilesResult = New UploadFilesResult()
                uploadFiles.name = file.FileName
                uploadFiles.size = file.ContentLength
                uploadFiles.type = "image/jpeg"
                uploadFiles.url = "/Content/uploads/" & file.FileName
                uploadFiles.deleteUrl = "/FileUploadHandler.ashx?file=" & file.FileName
                uploadFiles.thumbnailUrl = "/Content/uploads/" & file.FileName
                uploadFiles.deleteType = "GET"
                Dim jFiles As JsonFiles = New JsonFiles(resultList)
                Dim jFilesJson As String = JsonConvert.SerializeObject(jFiles)
                context.Response.ContentType = "text/plain"
            End If

            If context.Request.QueryString("file") IsNot Nothing Then
                File.Delete(Path.Combine(context.Server.MapPath("~/Content/uploads/"), context.Request.QueryString("file")))
                context.Response.ContentType = "application/json"
            End If
        End Sub

        Public ReadOnly Property IsReusable As Boolean
                Return False
            End Get
        End Property
    End Class
End Namespace

Open in new window

The code for the "fileupload.aspx" is the same as what is shown from the author's page, except I have vb instead of C#

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="fileupload.aspx.vb" Inherits="jFileUploadASP.fileupload" %>

Open in new window

Any assistance on this would be great.
Thank you, Wayne

C#Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon

Can you try this Nuget package instead?


Install it anyway, even though you may have done things manual, installing this package over it might solve all your problems.

Please note the description:

Query File Upload Plugin from blueimp (https://github.com/blueimp/jQuery-File-Upload). All files are included.

It looks like you're missing the two classes UploadFilesResult et JsonFiles. Maybe you forgot to include them in your project.
Wayne Barron

Hello, Kim.
I added the JQuery_File_Upload_Plugin through NuGet, but still nothing.
How do I reference it in the ashx file?

I understand that it is missing the two classes, UploadFilesResult & JsonFiles
That is what I am trying to figure out.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Wayne Barron

Found it. Oversite.

Public Class JsonFiles
    Public files As UploadFilesResult()
    Public Property TempFolder As String

    Public Sub New(ByVal filesList As List(Of UploadFilesResult))
        files = New UploadFilesResult(filesList.Count - 1) {}

        For i As Integer = 0 To filesList.Count - 1
            files(i) = filesList.ElementAt(i)
    End Sub
End Class

Public Class UploadFilesResult
    Public Property name As String
    Public Property size As Long
    Public Property type As String
    Public Property url As String
    Public Property deleteUrl As String
    Public Property thumbnailUrl As String
    Public Property deleteType As String
End Class

Open in new window

Wayne Barron

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

I had some compile issues when uploading the file(s), and it turned out to be the version difference in the Mewsoft.Json.dll file.
I replaced the ones I installed through NuGet with those in the author's folder, and it worked without issue.

I will look more into the new DLL file and see if there might be more references for the older version.