0

Get a full file path sent by the client in mvc

Ajax Call

   $("#btnCreateInvoice").click(function () {

    var id = $("#QuotId").val();
    var data = new FormData();
    var files = $("#FileUpload").get(0).files;
    if (files.length > 0) {
        data.append("FileUpload", files[0]);
        data.append("QuotId", id);



        $.ajax({
            type: "POST",
            url: "/Invoice/CreateInvoice",
            contentType: false,
            processData:false,
            data: data,


            success: function (response) {
                if (response.msg == "success") {
                    //  windows.location.href = "/Home/Index";
                    window.location.href = '@Url.Action("Index", "Home")';
                    alert("Your Invoice has been successfully created with " + response.id);
                }

            },

            error: function (response) {
                alert(response);
            }

        });
    }
});

ActionResult

  public ActionResult CreateInvoice(string QuotId)

    {
        var httpPostedFile = Request.Files["FileUpload"];
        var id = Request.Form["QuotId"];

        var filename = Path.GetFullPath(httpPostedFile.FileName);
    }

Actually the correct uploaded path file path is

E:\TrainingPrj\TrainingProject\Images\signlogo.jpg

and it shows me

C:\Program Files\IIS Express\signlogo.jpg

Arpit Shah
  • 37
  • 1
  • 9
  • 1
    The question is, why do you want full path of uploaded file when you have entire file data in httPostedFile? – Saket Kumar Jun 20 '17 at 18:20
  • @ArpitShah Sorry, I probably didn't understand what you want. What do you mean by the _full file path sent by the client_? The client is sending you a file content (plus some metadata like the file name), but definitely not any path, it wouldn't make any sense. I thought you want the path of the file on your server. But you need to save it there first (so you will know its path anyway). – David Ferenczy Rogožan Jun 20 '17 at 18:42

0 Answers0