Q:

How can I save images in a folder with javascript?  ASP.NET

with fileupload in asp.net, how can I save an image in a folder and then call and display it?  Can I use ajax, jquery or javascript with web method? 
<asp:FileUpload CssClass="image" ID="fileUpload" runat="server" />

I have these methods in c #, but I need it in javascript. 
 private void SaveFile(HttpPostedFile file)
        {
            string rut = Server. MapPath("~/temp");

            if (! Directory. Exists(rut))
            {
                Directory. CreateDirectory(rut);
            }

            string imgff= String. Format("{0}\\{1}", rut, file. FileName);

            if (File. Exists(imgff))
            {
                ClientScript. RegisterStartupScript(this. GetType(), "myalert", "Image()", true);
            }
            else
            {
                file. SaveAs(imgff);
            }
        }

With this method:
private void carga()
        {
            try
            {
                if (fileUpload. HasFile)
                {
                    // Se verifica que la extensión sea de un formato válido
                    string ext = fileUpload. PostedFile. FileName;
                    ext = ext. Substring(ext. LastIndexOf(".")  + 1).ToLower();
                    string[] formatos =
                      new string[] { "jpg", "jpeg", "bmp", "png" };
                    if (Array. IndexOf(formatos, ext) < 0)
                    {
                        ClientScript. RegisterStartupScript(this. GetType(), "myalert", "FormatoImagen()", true);
                    }
                    else
                    {
                        GuardarArchivo(fileUpload. PostedFile);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

A:

You can upload the file using the Generic Handler.  Using JQuery Ajax you can upload the files to the particular folder.  In the submit button call the JavaScript function
<input type="submit" value="Submit" onclick="return UploadFile();" />

JQuery Ajax
function UploadFile()
{
        $.ajax({
            url: "FileUploadHandler.ashx",
            type: "POST",
            data: data,
            contentType: false,
            async: false,
            processData: false,
            success: function (result) {
               // Process the result
            },
            error: function (err) {
                alert(err.statusText);
            }
        });
}

FileUploadHandler.ashx.cs
public class FileUploadHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        if (context. Request. Files. Count > 0)
        {
            HttpFileCollection files = context. Request. Files;
            for (int i = 0; i < files. Count; i++)
            {
                HttpPostedFile file = files[i];
                string extention = System. IO.Path. GetExtension(file. FileName);
                string fileName = file. FileName. Replace(extention, "") + Guid. NewGuid() + extention;
                string fname = context. Server. MapPath("~/FolderName/" + fileName);
                file. SaveAs(fname);
                context. Response. ContentType = "text/plain";
                context. Response. Write(fileName);
            }
        }
    }
}

For more information check this link

