Asp.Net Ajax Upload

Sağım solum önüm arkam AJAX ! Ajax ile dosya yüklemek işgence olmaktan çıkıyor desem sanırım abartmış olmam. Sayfa yeniden yüklenmediğinden dolayı kullanıcı seçtiği dosyayı sistemize yüklerken öte yandan formun geri kalanını rahatlıkla doldurabiliyor. jQuery nin Ajax Upload eklentisiyle iki dakika da upload işimizi halledebiliyoruz. Bu adreste klentinin demoları bulunuyor. Bu arada ben güvenlik sebebiyle örneğimde sadece .jpg dosyalarını yükletiyorum.

default.aspx

 $(document).ready(function() {
        /* Example 1 */
        var button = $('#button1'), interval;
        new AjaxUpload(button, {
            action: 'upload.aspx',
            name: 'myfile',
            onSubmit: function(file, ext) {
                // change button text, when user selects file
                button.text('Uploading');
                // If you want to allow uploading only 1 file at time,
                // you can disable upload button
                this.disable();
                // Uploding -> Uploading. -> Uploading...
                interval = window.setInterval(function() {
                    var text = button.text();
                    if (text.length < 13) {
                        button.text(text + '.');
                    } else {
                        button.text('Uploading');
                    }
                }, 200);
            },
            onComplete: function(file, response) {
                button.text('Upload');
                window.clearInterval(interval);
                // enable upload button
                this.enable();
                // add file to the list
                $('<li></li>').appendTo('#example1 .files').text(file);
            }
        });
    }); /*]]>*/</script>

        <ul>
	        <li id="example1" class="example">
		        <p>You can style button as you want</p>
		        <div class="wrapper">
			        <div id="button1" class="button">Upload</div>
		        </div>
		        <p>Uploaded files:</p>
		        <ol class="files"></ol>
	        </li>
        </ul>

Upload.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        HttpPostedFile hpfFile = Request.Files["myfile"];

        if (Path.GetExtension(hpfFile.FileName) == ".jpg")
        {
            hpfFile.SaveAs(Server.MapPath("~/ajaxUpload/" + hpfFile.FileName));
        }
    }

Örneğin demosuna
buradan
bakabilir, ilgili dosyaları

şuradan
indirebilirsiniz.

  • http://vestanbul.net Özgür

    Abdullah, demo dosyası uçmuş.

    • apoStyLEE

      Evet uçmuş, arşivimde de ilgili örnek bulunmuyor :S