2

I'm having some difficulty implementing the ajax control toolkit file upload. This is what i have coming up and the following is my code. I'm sorry for using VB, i was forced. If you know a C# solution please provide it and i will convert the code. Thank you

a busy cat

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="AMS.WebForm2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>

<form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />

    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" />
    <asp:Image ID="loader" runat="server"
        ImageUrl="~/loading.gif" Style="display: None" />
</form>
</body>
</html>

Code behind

Imports System.Web.Script.Serialization
Imports AjaxControlToolkit

Public Class WebForm2
Inherits System.Web.UI.Page

Protected Sub UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
    Dim path As String = Server.MapPath("Files/") + e.FileName
    AjaxFileUpload1.SaveAs(path)
End Sub
End Class
1

2 Answers 2

2

Your UploadComplete method will never be called because it is never handled. Add the UploadComplete event of the control like so:

Protected Sub UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete
    Dim path As String = Server.MapPath("Files/") + e.FileName
    AjaxFileUpload1.SaveAs(path)
End Sub

Since the file upload control is only saving the file to a temp location at this point since your handler is never called, I believe the error you're getting is related to not setting an HTTP handler. Otherwise, please specify the error.

Straight from the sample on the ajaxtoolkit site:

The AjaxFileUpload control uses an HTTP Handler named AjaxFileUploadHandler.axd This handler has the type AjaxControlToolkit.AjaxFileUploadHandler. You must add this handler to your Web.Config file in order for the AjaxFileUpload control to work.

Here's the Web.Config configuration that you must add:

<httpHandlers>
    <add verb="*" path="AjaxFileUploadHandler.axd"
      type="AjaxControlToolkit.AjaxFileUploadHandler, 
      AjaxControlToolkit"/>
</httpHandlers>

For IIS7:

<validation validateIntegratedModeConfiguration="false" />
<handlers>
    <add name="AjaxFileUploadHandler" verb="*" 
      path="AjaxFileUploadHandler.axd"
      type="AjaxControlToolkit.AjaxFileUploadHandler, 
      AjaxControlToolkit"/>
</handlers>

http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

thank you, it worked. Do you know how I can capture the bytes of that file so i can store it as binary in the database?
1

You must add the following in web.config to make it work.

<system.web>
    ....
    <httpHandlers>
        <add verb="*" path="AjaxFileUploadHandler.axd"
          type="AjaxControlToolkit.AjaxFileUploadHandler, 
          AjaxControlToolkit"/>
    </httpHandlers>
</system.web>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.