The uploaded file does not save in created folder

143 views Asked by At
<%@ 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;
        }
    }
}

i am trying to create directory and save the uploaded files in that directory.Folder is correctly creating in D drive but uploaded file are not saving in created folder. How to Solve.Thanks in Advance

0

There are 0 answers