上传的文件不会保存在已创建的文件夹中

时间:2017-01-04 05:37:26

标签: jquery asp.net ashx

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

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

public class Upload : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;
        try
        {
            string path = @"D:\" + "Test21";  // Give the specific path
            if (!(Directory.Exists(path)))
            {
                Directory.CreateDirectory(path);

                 HttpPostedFile postedFile = context.Request.Files["Filedata"];

            string savepath = "";
            string tempPath = "";
            System.Web.Configuration.WebConfigurationManager.AppSettings["FolderPath"].ToString(); 
            savepath = context.Server.MapPath(path);
            string filename = postedFile.FileName;

            postedFile.SaveAs(savepath + @"\" + filename);
            context.Response.Write(path + "\\" + filename);

            context.Response.StatusCode = 200;
            }




        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

我正在尝试创建目录并将上传的文件保存在该目录中。文件夹在D盘中正确创建,但上传的文件未保存在创建的文件夹中。如何解决。提前谢谢

0 个答案:

没有答案