Link to home
Start Free TrialLog in
Avatar of mcrmg
mcrmg

asked on

Dropzone upload Max file size

Hi,
I use Dropzone to upload the files to the site.
http://www.dropzonejs.com/#events

  
			<form id="upload" method="post" action="Docs.aspx" enctype="multipart/form-data">
			<div id="drop">
				Drag & Drop Here

				<a>Browse</a>
				<input type="file" name="upl" multiple />
			</div>

			<ul>
				<!-- The file uploads will be shown here -->
			</ul>

		</form>

Open in new window

this is the code behind

    protected void Page_Load(object sender, EventArgs e)
    {
        



        bool exists = System.IO.Directory.Exists(Server.MapPath("~/DocStorage/File-" + Session["sCMID"]));
        if (!exists)
            System.IO.Directory.CreateDirectory(Server.MapPath("~/DocStorage/File-" + Session["sCMID"]));

        DirectoryInfo flDis = new DirectoryInfo(Server.MapPath("~/DocStorage/File-" + Session["sCMID"]));

        foreach (string s in Request.Files)
        {
            HttpPostedFile file = Request.Files[s];
            int fileSizeInBytes = file.ContentLength;
            string fileName = file.FileName;
            string fileExtension = "";


            if (!string.IsNullOrEmpty(fileName))
                fileExtension = Path.GetExtension(fileName);
            string savedFileName = Guid.NewGuid().ToString() + fileExtension;
            //string savedFileName = fileName;

            string filename = Server.MapPath("~/DocStorage/File-" + Session["sCMID"] + "/" ) + savedFileName;
            

            file.SaveAs(filename);
            
        }



        FileInfo[] filesInDir = flDis.GetFiles("*.*");

        List<ListItem> files = new List<ListItem>();
        foreach (FileInfo foundFile in filesInDir)
        {
           files.Add(new ListItem(Path.GetFileName(foundFile.FullName), foundFile.FullName));
        }
        GridView1.DataSource = files;
         GridView1.DataBind();

        

    }

Open in new window


Everything works fine, but is there a way to set the max file size and file type? thanks
Avatar of leakim971
leakim971
Flag of Guadeloupe image

as you can see here : http://www.dropzonejs.com/#configuration
we have the parameter maxFilesize

Dropzone.options.upload = {
      maxFilesize: 2, // 2 MB
Avatar of mcrmg
mcrmg

ASKER

That is what puzzles me. Where do I put it? thanks
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just made a test to confirm it work :
User generated image
Avatar of mcrmg

ASKER

thank you very much