How to cast string to HttpFilePostedBase


Is there a way how to convert the string to HttpFilePostedBase? I'm currently using the <a href="http://valums.com/ajax-upload/" rel="nofollow">Ajax File upload</a> . But the value that it return is string. But my method is requesting for HttpFilePostedBase is there a way how to cast or convert it to HttpFilePostedBase?

here's my sample method in uploading files.

public bool uploadfiles(HttpPostedFileBase filedata) { bool status = false; //code for uploading goes here return status; }

How can i call this method if the ajax file upload is passing a string?


Are you using IE or Chrome/Firefox? cause, different browsers upload files in a different manner. IE uploads the files through Requres.Files but others use qqfile in the query string. Take a look <a href="https://stackoverflow.com/questions/4884920/mvc3-valums-ajax-file-upload" rel="nofollow">here</a> on how to use valums with mvc for different browsers

EDIT: Okay then, how about this. This is an example which worked for me:

public void ControllerUploadHandler() { // Set the response return data type this.Response.ContentType = "text/html"; try { // get just the original filename byte[] buffer = new byte[Request.ContentLength]; if (Request.QueryString["qqfile"] != null) { using (BinaryReader br = new BinaryReader(this.Request.InputStream)) br.Read(buffer, 0, buffer.Length); } else if (Request.Files.Count > 0) { HttpPostedFileBase httpPostedFileBase = Request.Files[0] as HttpPostedFileBase; using (BinaryReader br = new BinaryReader(httpPostedFileBase.InputStream)) br.Read(buffer, 0, buffer.Length); } else this.Response.Write(" {'success': false }"); // return the json object as successful this.Response.Write("{ 'success': true }"); this.Response.End(); return; } catch (Exception) { // return the json object as unsuccessful this.Response.Write("{ 'success': false }"); this.Response.End(); } }


You can't. You can access files posted to an aspx page via the HttpContext.Request.Files property.


  • A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property “How t
  • Why does JPA TypedQuery throw Exception: Parameter value […] did not match expected type [java.lang.
  • asp.net mvc - Detecting page refresh
  • Newtonsoft inline formatting for subelement while serializing
  • Why is RAM in powers of 2?
  • Visual basic auto imports namespaces
  • Update partial with Ajax in Rails 3
  • Sencha Touch 2.1 native (android) app not getting json from remote (it works on PC)
  • WPF Listbox commands
  • Making a URL W3C valid AND work in Ajax Request
  • Attemping to change attributes of $(this) inside success function
  • Why does IE8 fail to resolve my JQuery selector for a checked radio option?
  • how to display   in Mozilla using XSL.
  • jQueryMobile, Ajax Navigation, and MVC
  • PHP get selected value of select form
  • How do I check if System::Collections:ArrayList is empty / nullptr / null?
  • Creating a C++ function that calls other Lua function
  • Is there a way to set up a fallback for the formAction attribute in HTML5?
  • Google OAuth: can't get refresh token with authorization code
  • Responsive design method for collapsing a div
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • PayPal API Listener Website Payments Standard URI
  • How to use function wrapper in mustache.php?
  • Repository Browser Only - \"Repository moved permanently to… please relocate”
  • Hide HTML elements without javascript, only CSS
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Adjust width of select element according to selected option's width
  • Is playing sound in Javascript performance heavy?
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Django rest serializer Breaks when data exists
  • Display issues when we change from one jquery mobile page to another in firefox
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Javascript convert timezone issue
  • Statically linking a C++ library to a C# process using CLI or any other way
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • How can I remove ASP.NET Designer.cs files?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?
  • java string with new operator and a literal