using swfUpload in asp.net mvc
2013-05-25 17:31
501 查看
1.download swfupload.js
2.in action,implete multi file upload
@{ ViewBag.Title = "AddProduct"; } <h2> AddProduct</h2> <div> <fieldset> <legend>Add product</legend> <div class="form_item"> <div class="item_title"> product name</div> <div class="item_input"> <input type="text" id="name" /></div> </div> <div class="form_item"> <div class="item_title"> product catagory</div> <div class="item_input"> <select> <option value="">please select</option> </select> <a href="#">click here to add or edit catagory</a></div> </div> <div class="form_item"> <div class="item_title"> product description</div> <div class="item_input"> <textarea id="description" rows="10" cols="100"></textarea></div> </div> <div class="form_item"> <div class="item_title"> product price</div> <div class="item_input"> <input type="text" id="price" /></div> </div> <div class="form_item"> <div class="item_title"> product image</div> <div> <span id="spanButtonPlaceHolder"></span> <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" /> </div> <div class="fieldset flash" id="fsUploadProgress"> <span class="legend">Upload Queue</span> </div> <div id="divStatus">0 Files Uploaded</div> </div> <div class="form_item"> <div class="item_input"> <input type="button" value="confirm" /> <input type="button" value="reset" /></div> </div> </fieldset> </div> <script src="http://www.cnblogs.com/Scripts/swfupload/fileprogress.js" type="text/javascript"></script> <script src="http://www.cnblogs.com/Scripts/swfupload/handlers.js" type="text/javascript"></script> <script src="http://www.cnblogs.com/Scripts/swfupload/swfupload.js" type="text/javascript"></script> <script src="http://www.cnblogs.com/Scripts/swfupload/swfupload.queue.js" type="text/javascript"></script> <script type="text/javascript"> var swfu; window.onload = function () { var settings = { flash_url: '@Url.Content("~/Scripts/Swfupload/swfupload.swf")', upload_url: '/admin/imageupload', post_params: { "PHPSESSID": "" }, file_size_limit: "100 MB", file_types: "*.*", file_types_description: "All Files", file_upload_limit: 100, file_queue_limit: 0, custom_settings: { progressTarget: "fsUploadProgress", cancelButtonId: "btnCancel" }, debug: false, // Button settings button_image_url: '@Url.Content("~/Scripts/Swfupload/images/XPButtonNoText_160x22.png")', //flash按钮背景,注意自己的路径。 button_width: "65", button_height: "29", button_placeholder_id: "spanButtonPlaceHolder", button_text: '<span class="theFont">Hello</span>', button_text_style: ".theFont { font-size: 16; }", button_text_left_padding: 12, button_text_top_padding: 3, // The event handler functions are defined in handlers.js file_queued_handler: fileQueued, file_queue_error_handler: fileQueueError, file_dialog_complete_handler: fileDialogComplete, upload_start_handler: uploadStart, upload_progress_handler: uploadProgress, upload_error_handler: uploadError, upload_success_handler: uploadSuccess, upload_complete_handler: uploadComplete, queue_complete_handler: queueComplete // Queue plugin event }; swfu = new SWFUpload(settings); }; </script>
2.in action,implete multi file upload
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.IO; namespace PlantWeb.Controllers { public class AdminController : Controller { // // GET: /Admin/ public ActionResult Add() { return View(); } public ActionResult Edit() { return View(); } public ActionResult ImageUpload() { int files = 0; string root_path = AppDomain.CurrentDomain.BaseDirectory; string upload_path = root_path + @"UploadImage\product"; string upload_filename = ""; if (!Directory.Exists(upload_path)) { Directory.CreateDirectory(upload_path); } foreach (string filename in Request.Files) { //保存的本地 var file = Request.Files[filename]; upload_filename = file.FileName; file.SaveAs(upload_path + "\\" + upload_filename); files++; //保存到数据库 //byte[] buffer; //buffer = new byte[file.InputStream.Length]; //file.InputStream.Read(buffer, 0, buffer.Length); } return Content("message from server file count: " + files, "text/plain"); } } }
相关文章推荐
- using swfUpload in asp.net mvc
- http://venkatbaggu.com/file-upload-in-asp-net-mvc-using-dropzone-js-and-html5/
- File Upload using jQuery AJAX in ASP.NET Web API or Http handler (AJAX上传文件通过Web API或 http handler)
- 【转】In ASP.NET using jQuery Uploadify upload attachment
- Using JQuery to perform Ajax calls in ASP.NET MVC
- Creating a NuGet Package in 7 easy steps - Plus using NuGet to integrate ASP.NET MVC 3 into existing Web Forms applications
- Upload Large Files in ASP.NET Using HttpModule
- Rendering a Form in ASP.NET MVC Using HTML Helpers
- 转:Setting Up IoC in ASP.NET MVC using Castle Windsor
- Upload Multiple Files in ASP.NET using jQuery
- Using Membership in ASP.Net MVC 4 (转)
- Upload files in ASP.NET MVC with JavaScript and C#
- Integrating OpenID in an ASP.NET MVC Application using DotNetOpenAuth
- Upload Large Files in ASP.NET Using HttpModule
- Using JSONP in ASP.NET MVC
- MVC architecture in ASP.Net using C# and Microsoft Data Access Application block
- HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual Basic .NET
- CRUD Operations In ASP.NET MVC 5 Using ADO.NET
- Saving and Displaying Photos in SQL Server using ASP.NET and FileUpload Control
- MVC architecture in ASP.Net using C#