Как сохранить загруженные файлы pdf, doc, jpg в папке, используя jquery и asp.net (aspx pages) - PullRequest
1 голос
/ 20 октября 2019

Я пробовал это, но это не работает, так как отладчик не запускает веб-метод в файле c #. Код C #

[WebMethod]
public static string DocumentUpload()
{

        var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
        if (httpPostedFile != null)
        {
            var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/DistributorDocument/DistributorEnrollmentDocument/" + HttpContext.Current.Session["UserId"].ToString()), httpPostedFile.FileName);

            // Save the uploaded file to "UploadedFiles" folder
            httpPostedFile.SaveAs(fileSavePath);
        }
        return "";
}

Вот код jquery, который я использую при загрузке файла. я пытаюсь загрузить файл типа doc, pdf, jpg. Пожалуйста, помогите мне, поскольку я новичок в asp.net

$(document).ready(function () {
$('.uploadedFile').on('change', function (e) {

    var documentDescription = '';

    documentDescription = e.target.name.split('.').pop();

    var fileName = "";

    var documentType = $(this).val().split('.').pop().toLowerCase();
    fileName = e.target.files[0].name;

    var data = new FormData();
    var files = $("#" + e.target.id).get(0).files;
    if (files.length > 0) {
        data.append("UploadedImage", files[0]);
    }

    $.ajax({
        type: "POST",
        url: "DistributorEnrollmentForm.aspx/DocumentUpload",
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        success: function (response) {
            var msg = response.d;
            if (msg == "success") {
                $.notify('Data saved successfully', {
                    style: 'happyblue',
                    className: 'superblue'
                });
            }
            $('#uploadDocumentPassport_DL').val('');
        },
        error: function (xhr, ajaxOptions, thrownError) {
            document.location.reload(true);
        }
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...