【问题标题】:How to upload the multiple files using fileuploader and save database usaing asp.net and sql server2008如何使用文件上传上传多个文件并使用 asp.net 和 sql server 2008 保存数据库
【发布时间】:2011-12-30 09:42:02
【问题描述】:

我正在使用文件上传器或asyncfileuploader上传多个文件,以基于逗号(,)将文件名存储在数据库sql server表列中,并且还保存在我的应用程序特定文件夹中,另一件事是文件名替换为我们的 id 和扩展名(例如:10001A1.JPEG、10001A2.doc 等也存储到数据库和文件夹),如何编写多个上传文件的代码请给我任何建议。

我有根据这个网址找出解决方案check this

but now my problem is uploading multiple files, after select the dropdown(selected event fired) field page will post back that time multiple file will be lose and another thing is first select the drop down after select the file upload , file upload is not working pls give me some suggestion

谢谢你 赫曼斯

【问题讨论】:

    标签: sql-server-2008 c#-4.0 file-upload asp.net-4.0


    【解决方案1】:

    上面的问题答案是先添加jquery文件点击下面的链接jquey all files

    Step 1: Open Visual Studio 2008 > File > New > Website > Choose ‘ASP.NET 3.5 website’ from the templates > Choose your language (C# or VB) > Enter the location > Ok. In the Solution Explorer, right click your project > New Folder > rename the folder as ‘Scripts’.
    Step 2: Download jQuery 1.3.2 , jQuery VS 2008 Doc and the Multiple File Upload PlugIn. Create a ‘Scripts’ folder in the Solution Explorer of your project and add these files to this folder.
    Assuming you have downloaded these files, create a reference to these files in the <head> section of your page as shown below:
    <head runat="server">
        <title></title>
            <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
            <script src="Scripts/jquery.MultiFile.js" type="text/javascript"></script>
    </head>
    
    Step 3: Now drag and drop an ASP.NET ‘FileUpload’ control from the toolbox to the page. Also add a Button control to the page. This Button control will trigger the upload to the server.
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
            <br />
            <asp:Button ID="btnUpload" runat="server" Text="Upload All"
                onclick="btnUpload_Click" />
        </div>
    
    Observe that the FileUpload has class=”multi” set on it. This attribute is mandatory.
    Step 4: The last step is to add code to upload button. Add the following code:
    C#
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                // Get the HttpFileCollection
                HttpFileCollection hfc = Request.Files;
                for (int i = 0; i < hfc.Count; i++)
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("MyFiles") + "\\" +
                          System.IO.Path.GetFileName(hpf.FileName));
                        Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +
                            hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
                    }
                }
            }
            catch (Exception ex)
            {
    
            }
        }
    

    它正在工作,但你在上传该文件的文件被删除后回发,所以最后上传任何页面中的文件对check this link有任何疑问

    【讨论】:

      【解决方案2】:

      Update panel 中包含Dropdown 怎么样

      <asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
      <Triggers>
      <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
      </Triggers>
      <ContentTemplate>
      <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true"
      onselectedindexchanged="ddl_SelectedIndexChanged">
      <asp:ListItem Text="Hi"></asp:ListItem>
      <asp:ListItem Text="Hello"></asp:ListItem>
      </asp:DropDownList>
      </ContentTemplate>
      </asp:UpdatePanel>
      

      【讨论】:

      • ddl 工作但图像按钮和单击事件不起作用如何在图像按钮中编写 asyncpostbacktrigger
      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 2022-08-06
      • 1970-01-01
      • 2013-09-29
      • 2016-08-10
      • 2012-12-04
      • 2011-10-22
      • 1970-01-01
      相关资源
      最近更新 更多