Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6641065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:46:00+00:00 2026-05-25T23:46:00+00:00

I am using Jquery ajax to Upload files to my database to produce a

  • 0

I am using Jquery ajax to Upload files to my database to produce a progress bar..

The problem is, I have no way of passing the uploaded filename to my backend code. I can easily enough pass the filename that was sent via the user using Hiddenfields and jquery, however my ASHX Handler may have renamed it if that file exists. I tried to create a Session[“variable”] in the ASHX file with the passed context, however it was null..

Here is my Javascript :

$(function () {
    $("#<%=supplierInfo.FUclientID %>").makeAsyncUploader({
        upload_url: '<%=ResolveUrl("~/Controls/UploadHandler.ashx")%>', // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file, or an ASP.NET .ASHX handler. The handler should save the file to disk (or database).
        flash_url: '../../Scripts/swfupload.swf',
        button_image_url: '../../Scripts/blankButton.png',
        disableDuringUpload: 'INPUT[type="submit"]',
        upload_success_handler: function () {
            var hiddenfield = document.getElementById('<% =hdnTest.ClientID %>');
            hiddenfield.value = "test";

            $("span[id$=_completedMessage]", container).html("Uploaded <b>{0}</b> ({1} KB)"
                        .replace("{0}", file.name)
                        .replace("{1}", Math.round(file.size / 1024))
                    );
        }
    });
});

The ASHX Handler:

<%@ WebHandler Language="C#" Class="UploadHandler" %>

using System;
using System.Web;
using System.IO;

public class UploadHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
        string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();

        int i = 0;
        while (File.Exists(context.Server.MapPath("~/images/Upload/SupplierImg") + "/" + strFileName))
        {
            strFileName = Path.GetFileNameWithoutExtension(strFileName) + i.ToString() + strExtension;
        }

        string strLocation = context.Server.MapPath("~/images/Upload/SupplierImg") + "/" + strFileName;
        context.Request.Files[0].SaveAs(strLocation);

        context.Response.ContentType = "text/plain";
        context.Response.Write("OK");

    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:46:01+00:00Added an answer on May 25, 2026 at 11:46 pm

    Make sure you are explicitly declaring the content type in your jQuery AJAX call.

    $.ajax({
      type: "POST",
      url: "UploadHandler.ashx",
      data: "{ 'fileName' : 'myFileName' }",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(data) {
               // This may be data.d depending on what version of .NET you are running
               //     See this link for more info on .d - http://haacked.com/archive/2009/06/25/json-hijacking.aspx
    
               $("span[id$=_completedMessage]", container).html("Uploaded <b>{0}</b> ({1} KB")
                        .replace("{0}", data.fileName)
                        .replace("{1}", Math.round(data.fileSize / 1024))
               );
      }
    });
    

    And you may want to pre-serialize your data on the server:

    public void ProcessRequest (HttpContext context) {
    
        string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
    
    ...
    
        context.Response.ContentType = "text/plain";
        context.Response.Write(JsonConvert.SerializeObject(new { fileName = strFileName, fileSize = iFileSize }));
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery Form Plugin to upload my files via AJAX and I
I'm posting data using jquery/ajax and PHP at the backend. Problem being, when I
So I have a system using jQuery AJAX to load the content dynamically. I
I have some content that I am loading using jquery ajax. The content has
I am using codeigniter and Jquery. I have an upload form in my view
I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/
I'm using the jQuery plugin ajaxForm to submit a file upload form via AJAX.
I'm using jquery form plugin http://jquery.malsup.com/form/#getting-started to upload images through ajax. When I try
I'm using the script from http://webdeveloperplus.com/jquery/ajax-multiple-file-upload-form-using-jquery/ I modified the onComplete to add a link
I've got a problem sending a file to a serverside PHP-script using jQuery's ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.