开发者

Display images after uploading with uploadify in asp.net

I am trying to upload images using jquery uploadify and I am trying to display images in the data list view control.

The problem is I am not able to upload multiple images at a time although I have set the "Multi" property to "TRUE".

I'm not understanding where I am going wrong?

Here is my code:

<script type = "text/javascript">

$(document).ready(function()
{   
    $("#<%=FileUpload1.ClientID%>").uploadify({
        'uploader'       : 'scripts/uploadify.swf',
        'script'         : 'Upload.ashx',
        'cancelImg'      : 'images/cancel.png',
        'folder'         : 'uploads',
        'multi'          : true,
        'auto'           : true,
        'onComplete': function (event, queueID, fileObj, response, data) {
                     $('#dtlist).append('<img src="' + response + '" />');
      }
   });

});     

Upload.ashx code:

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

Imports System Imports System.Web Imports System.IO

Public Class UploadVB : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")

    Dim savepath As S开发者_如何转开发tring = ""
    Dim tempPath As String = ""

    tempPath = context.Request("folder")

    'If you prefer to use web.config for folder path, uncomment below:
    'tempPath = System.Configuration.ConfigurationManager.AppSettings("FolderPath")


    savepath = context.Server.MapPath(tempPath)
    Dim filename As String = postedFile.FileName
    If Not Directory.Exists(savepath) Then
        Directory.CreateDirectory(savepath)
    End If

    postedFile.SaveAs((savepath & "\") + filename)
    context.Response.Write((tempPath & "/") + filename)
    context.Response.StatusCode = 200
End Sub

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

End Class

And this my front end code:

 <form id="form1" runat="server">
        <br/>
        <div class="demo">

            <asp:FileUpload ID="FileUpload1" runat="server" />

            <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" 
                Text="Upload" />

        </div>
        </form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜