Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c# - Using dropzone.js in asp.net

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/

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Example .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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...