Example:
If I want to upload a picture to the server side: ASP page
Copy Code code as follows:
<form id= "Form1" runat= "Server" action= "/bookindex/fileupload/" (you are prepared to process ActionResult) "method=" POST "enctype=" Multipart/form-data ">
<input type= "File" id= "Imageupload" name= "Imageupload" >
<input type= "button" value= "click to upload" onclick= "UpLoad ()" >
....
</form>
JS Code:
Copy Code code as follows:
<script type= "Text/javascript" >
function UpLoad ()
{
If there are other values, determine if the bottom is empty.
Form1.submit ();
}
<script>
Background code
Copy Code code as follows:
Public ActionResult FileUpload (HttpPostedFileBase imageupload (consistent with front page input box name)
{
string fileName = Imageupload.filename;
The conversion only gets the filename and removes the path.
if (Filename.lastindexof ("\") >-1)
{
FileName = filename.substring (Filename.lastindexof ("\") + 1);
}
Save to a relative path.
Imageupload.saveas (Server.MapPath) (". /.. /image/img/"+ fileName));
The following code is to save the path to the database.
String ImagePath = ".. /.. /image/img/"+ fileName;
String sql = "INSERT into BookInfo (Bookphoto) VALUES (' + ImagePath + ')";
Encapsulated code, called directly.
Database db = new database ();
Db.getconn ();
int result = db.executeupdate (SQL);
return View ();
}