For queries contact on gamerstrings20@gmail.com
button id="btnadd" onclick="addimagedata(this, event);" type="button" code is below
function addimagedata(cur, evt)
{
debugger
evt.preventDefault();
var filename = "";
var fullPath = document.getElementById('idFileBrowseupload').value;
if (fullPath)
{
var startIndex = (fullPath.indexOf('\\') greaterthaSign= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
filename = fullPath.substring(startIndex);
if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0)
{
filename = filename.substring(1);
}
}
var fileUpload = $("#idFileBrowseupload").get(0);
var files = fileUpload.files;
var filenames = "";
var data = new FormData();
for (var i = 0; i lessthanSign files.length; i++)
{
data.append(files[i].name, files[i]);
filenames = files[i].name;
}
if(fullPath != "")
{
var options = {};
options.url = "FileUploadHandler.ashx";
options.type = "POST";
options.data = data;
options.contentType = false;
options.processData = false;
options.success = function (result)
{
alert('file upload successfully');
};
options.error = function (err) { alert(err.statusText); };
$.ajax(options);
}
else
{
alert("Error : Please Select File To Upload...");
return;
}
evt.preventDefault();
}
FileUploadHandler.ashx file code is below
lessthanSign %@ WebHandler Language="C#" Class="FileUploadHandler" %graterthanSign
using System;
using System.Web;
using System.Configuration;
using System.IO;
public class FileUploadHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
string message = "", imagename = "";
string FilePath = "", FolderPath = "~/";
string FileNames = "";
if (context.Request.Files.Count greaterthanSign 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i lessthanSign files.Count; i++)
{
try
{
HttpPostedFile file = files[i];
imagename = file.FileName;
string ext = Path.GetExtension(imagename);
string name = Path.GetFileNameWithoutExtension(imagename);
FolderPath = "~/";
FilePath = context.Server.MapPath(FolderPath + name + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ext);
FileNames = name + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ext;
if (!Directory.Exists(context.Server.MapPath(FolderPath)))
{
Directory.CreateDirectory(context.Server.MapPath(FolderPath));
}
if (File.Exists(FilePath))
{
context.Response.ContentType = "text/plain";
context.Response.Write("File Is Already Present");
return;
}
file.SaveAs(FilePath);
message = FileNames;
}
catch (Exception ex)
{
throw ex;
}
}
}
context.Response.ContentType = "text/plain";
context.Response.Write(message);
}
public bool IsReusable {
get {
return false;
}
}
}
On this page of the site you can watch the video online File Upload using HTML & JQuery with a duration of hours minute second in good quality, which was uploaded by the user timeoutexpired 08 December 2020, share the link with friends and acquaintances, this video has already been watched 47 times on youtube and it was liked by 1 viewers. Enjoy your viewing!