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"
resultList.Add(uploadFiles)
Dim jFiles As JsonFiles = New JsonFiles(resultList)
Dim jFilesJson As String = JsonConvert.SerializeObject(jFiles)
context.Response.ContentType = "text/plain"
context.Response.Write(jFilesJson)
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"
context.Response.Write("OK")
End If
End Sub
Public ReadOnly Property IsReusable As Boolean
Get
Return False
End Get
End Property
End Class
End Namespace
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" %>
Any assistance on this would be great.
Thank you, Wayne
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)
Next
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
https://www.nuget.org/packages/JQuery_File_Upload_Plugin/
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.