Code behind to look for correct folder on server
I have two folders in my site's root folder. One is the folder that holds the files for downloading and other is the application folder for code behind. For downloading a file, the code behind interacts with my HTML page for downloading. I am using the method of response.transmitfile. When ever i try to download the file of applications that is uploaded to file, then instead of going to the root of the site and then into the folder for downloading, it tries to pull it from the application folder. Am i missing something with the transmitfile method? My downloadfile code is as given below. Pls tell me if there is something wrong.
Code:
public void fileDownload(string filePath, string fileName)
{
fileName = System.IO.Path.GetFileName(filePath);
if (fileName != null)
{
try
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Content-length", fileName.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachement; filename=" + fileName);
HttpContext.Current.Response.ContentType = "application/exe";
HttpContext.Current.Response.TransmitFile("/programs/" + answerClicked + ".exe");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write("Error: " + ex.Message);
}
}
else
{
HttpContext.Current.Response.Write("Error: File Not Found");
}
return;
}