2013-08-22 50 views
0

我創建上傳簡歷的方法。它沒有顯示任何錯誤。當我打開它顯示爲空文件..沒有數據..上傳文件存儲0值

我控制器

 [HandleErrorWithAjaxFilter] 
    public ActionResult UploadResume(HttpPostedFileBase FileData) 
    { 
     Stream fromStream = FileData.InputStream; 
     Stream toStream = new FileStream(Server.MapPath("~/Content/Resumes/") + FileData.FileName, FileMode.Create); 

     LoggedInCandidate.ResumeFileName = FileData.FileName; 
     //_repository.Save(); 
     _userRepository.Save(); 

     return Json(new JsonActionResult 
     { 
      Success = true, 
      Message = "Resume has been uploaded." 
     }); 
     //return Json("Resume has been uploaded."); 
    } 

查看:

<input id="Resume" type="file" name="Resume" />  

的Jquery:

Models.Candidate.AddUploadResumeBehavior = function() { 
$('#Resume').uploadify({ 
    'swf': root + '/Content/Flash/uploadify.swf', 
    'uploader': root + '/Candidates/UploadResume', 
    'cancelImg': root + '/Content/Images/uploadify-cancel.png', 
    'auto': true, 
    'multi': true, 
    'fileDesc': 'Image Files', 
    'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg;*.doc', 
    'queueSizeLimit': 90, 
    'sizeLimit': 4000000, 
    'buttonText': 'Upload Resume', 
    'width': 200, 
    'folder': root + '/uploads', 
    'onComplete': function (event, queueID, fileObj, response, data) { 
     Models.Candidate.ShowMessageBar("Resume has been uploaded."); 
    }, 
    'onError': function (event, ID, fileObj, errorObj) { 
     var msg; 
     if (errorObj.type === "File Size") 
      msg = 'File size cannot exceed 4MB'; 
     else 
      msg = "An error occured while attempting to uploading resume." 

     Models.Candidate.ShowMessageBar(msg); 
     this.hide(); 
    } 
}); 

};

請找到問題並幫助我。

回答

0

您在代碼中沒有使用fromStream ...您只是創建一個新文件並將其關閉。因此0字節長度。

在.NET 4中,你可以這樣做:

Stream fromStream = FileData.InputStream; 
Stream toStream = new FileStream(Server.MapPath("~/Content/Resumes/") + FileData.FileName, FileMode.Create); 

// Actually upload the bytes! 
fromStream.CopyTo(toStream);