Ajaxfileupload和图像

时间:2014-02-28 12:47:26

标签: asp.net sql-server vb.net file-upload

我无法上传我的图片为什么?我有这个错误,有人可以帮忙,我真的迷失了一周,请

        If Page.IsPostBack = False Then
        ' Getting the File Name 
        Dim filename As String = e.FileName

        ' Setting the path to upload Images

        AjaxFileUpload1.SaveAs(Server.MapPath("images/") & filename)

        ' Storing the relative path to store into images
        Dim Imagepath As String = "~/Seller/images/" & filename
        Dim conss As New SqlConnection(_start)
        conss.Open()


        Dim sql1 As String = "INSERT INTO Image(Image,ItemID) VALUES (@image,@item)"
        Dim myCommand1 = New SqlCommand(sql1, conss)

        myCommand1.Parameters.AddWithValue("@image", Imagepath)
        myCommand1.Parameters.AddWithValue("@item", dbItem.SelectedValue)
        myCommand1.ExecuteNonQuery()
        Response.Redirect("ItemView.aspx")

enter image description here

    

<div>
    <asp:Label ID="Label1" runat="server" Text="Select Auction:"></asp:Label> <asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:DropDownList ID="dbItem" AutoPostBack="true"  DataValueField="ItemID" DataTextField="Name"  
                runat="server" >

            </asp:DropDownList></ContentTemplate></asp:UpdatePanel>
<asp:Label runat="server" ID="myThrobber" Style="display: none;"></asp:Label>
    <asp:AjaxFileUpload ID="AjaxFileUpload1" ThrobberID="myThrobber" MaximumNumberOfFiles="4" AllowedFileTypes="jpg,jpeg" runat="server" />
</div>

1 个答案:

答案 0 :(得分:0)

在web.config文件夹中。 。 。添加此部分

<configuration>
   <location path="AjaxFileUploadHandler.axd">
       <system.web>
          <authorization>
             <allow users="*"/>
          </authorization>
       </system.web>
   </location> 

在root web.config中,添加此处理程序

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

开发时,如果您使用的是Windows7或Windows8,请运行visual studio AS ADMINISTRATOR