I am trying to accept files for upload through the httphandler and I need the path I have coming from a drop down list in the .aspx. I have the path as a variable in the aspx.cs file but I can't access it in the .ashx file. I think it has to do with the web.config file I added reference for the .ashx to the system.web configuration but no change.
'<%@ WebHandler Language="C#" Class="FileHandler" %>'
using System;
using System.Web;
public class FileHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach(string key in files)
{
HttpPostedFile file = files[key];
string fileName = context.Server.MapPath("thisIsWhereINeedThePath" + key);
file.SaveAs(fileName);
}
context.Response.ContentType = "text/plain";
context.Response.Write("Great");
}
}
public bool IsReusable {
get {
return false;
}
}
}
I tried to pass the path from Jquery but had trouble with 2 data types being passed in the post.
This is from the aspx.cs file, I am trying to get the value of the listDrop.SelectedItem.Text
protected void ListDrop_SelectedIndexChanged(object sender, EventArgs e)
{
string fullFileName = Path.Combine("~/Uploads/", listDrop.SelectedItem.Text);
string[] filePaths = Directory.GetFiles(Server.MapPath(fullFileName));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
}