在asp.net中使用uploadify上传后显示图像

时间:2011-09-03 10:53:04

标签: jquery asp.net uploadify

我正在尝试使用jquery uploadify上传图像,我正在尝试在数据列表视图控件中显示图像。

问题是我无法一次上传多张图片although我已设置"Multi" property to "TRUE".

我不明白我哪里出错了?

这是我的代码:

<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代码:

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

进口系统 进口System.Web Imports System.IO

Public Class UploadVB:实现IHttpHandler

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

    Dim savepath As String = ""
    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

结束班

这是我的前端代码:

 <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 个答案:

没有答案
相关问题