Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-09-2008
Member
 
Join Date: Apr 2008
Posts: 242
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;
}
Reply With Quote
  #2  
Old 06-09-2008
Member
 
Join Date: Nov 2005
Posts: 1,323
The problem is that you are using a relative path to transmit the file. You application is running in the applications folders, it will attempt to transmit the file starting from that location.

You need to use:

Server.MapPath()

the change you make would be:
Code:
HttpContext.Current.Response.TransmitFile(this.Context.Server.MapPath("/programs/" + answerClicked + ".exe"));
This method will map your relative directory "/programs/" + answerClicked + ".exe", to a physical one, starting from your sites root directory i.e

c:\inetpub\wwwroot\programs\<answerClicked>.exe
Reply With Quote
  #3  
Old 06-09-2008
Member
 
Join Date: Apr 2008
Posts: 242
I tried this thing. It still goes to the application folder looking for the program to download. To get it downloaded from the different folder, i think i will need to try a different approach. Thank you for the reply.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Code behind to look for correct folder on server"
Thread Thread Starter Forum Replies Last Post
PHP code to copy one folder into another folder Svetlana Software Development 2 12-04-2012 05:05 PM
On Ubuntu, Getting C Source code from Cache folder of Seamonkey Popeyee Operating Systems 2 01-12-2011 04:10 PM
How to correct firewall rules in ISA server to apple Facetime working on iPhone 4 Nimos Portable Devices 9 05-09-2011 10:36 PM
Error code 36 in Mac OS X when copying folder dogaman Operating Systems 6 11-11-2010 12:03 AM
Getting an ERROR when trying to compile the Correct Code!? Beter 2 Burn Out Software Development 5 02-01-2010 08:30 PM


All times are GMT +5.5. The time now is 07:25 AM.