C# 在 asp.net 中使用 dropzone.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16050965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:49:53  来源:igfitidea点击:

Using dropzone.js in asp.net

c#javascriptjqueryasp.net

提问by Hakuna Matata

Since few days i m trying to implement multiple file upload with drag and drop interface. I have searched a lot and at last found my exact requirement from http://www.dropzonejs.com/

几天以来,我试图通过拖放界面实现多文件上传。我搜索了很多,最后从http://www.dropzonejs.com/找到了我的确切要求

I tried same steps from above site. but, I am unable to implement this dropzone functionality in my aspx page.

我从上面的网站尝试了相同的步骤。但是,我无法在我的 aspx 页面中实现这个 dropzone 功能。

采纳答案by Arsen

Assuming you are using Web Forms, you need to implement a page that reads the posted file data and saves it to file.

假设您正在使用 Web 窗体,您需要实现一个页面来读取发布的文件数据并将其保存到文件中。

Example .ASPX

示例 .ASPX

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Mvc4Application_Basic.WebForm1" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://raw.github.com/enyo/dropzone/master/downloads/dropzone.js"></script>
        <link href="http://www.dropzonejs.com/css/general.css?v=7" rel="stylesheet" />
    </head>
    <body>
        <form id="frmMain" runat="server" class="dropzone">
            <div>
                <div class="fallback">
                    <input name="file" type="file" multiple />
                </div>
            </div>
        </form>
    </body>
    </html>

Example code-behind

示例代码隐藏

    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (string s in Request.Files)
            {
                HttpPostedFile file = Request.Files[s];

                int fileSizeInBytes = file.ContentLength;
                string fileName = Request.Headers["X-File-Name"];
                string fileExtension = "";

                if (!string.IsNullOrEmpty(fileName))
                    fileExtension = Path.GetExtension(fileName);

                // IMPORTANT! Make sure to validate uploaded file contents, size, etc. to prevent scripts being uploaded into your web app directory
                string savedFileName = Path.Combine(@"C:\Temp\", Guid.NewGuid().ToString() + fileExtension);
                file.SaveAs(savedFileName);
            }
        }
    }

If you are using MVC, see this https://stackoverflow.com/a/15670033/2288997

如果您使用的是 MVC,请参阅此https://stackoverflow.com/a/15670033/2288997