0

Im having a asp.net application run on IIS 7.5 In one of the pages, there is a " view file" link. This points to( in code) a physical directory eg: D:\Campoff\policy.

Whenever the user clicks on the link, a file under that physical directory get downloaded. However, when i run the application on IIS, when i point to that " View file" link, it points to http://localhost/Campoff/policy. this gives the 404 error( FIle not found).

The location of the physical directory is in Web.config file in a key value pair.And that is being addressed in the code.

Here's what I'm calling

protected string getLinkText(string policyNo) 
{ 
    string str = ""; 
    if (File.Exists(ConfigurationManager.AppSettings.Get("Insurance‌​PolicyFileDir") + 
        policyNo + ".pdf")) 
        str = policyNo; 
        return str; 
} 

str ends up being localhost/insurancepolicydir instead of d:\insurancepolicydir

Please help me understand, what is happening or what is wrong with my setting?

SaraDob
  • 77
  • 11
  • You CANNOT download a file using a file URI through a browser. You must serve the file through the website. There's tons of info out there about how to serve static or dynamic files via asp.net. Search for "asp.net how to download a file" and get results like http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-asp-net-mvc –  Jan 11 '17 at 14:10
  • You can describe your code for a year, or you could simply [edit] and show us your actual code. –  Jan 11 '17 at 14:25
  • This is the code that gets called , when the text link is clicked. protected string getLinkText(string policyNo) { string str = ""; if (File.Exists(ConfigurationManager.AppSettings.Get("InsurancePolicyFileDir") + policyNo + ".pdf")) str = policyNo; return str; } The str is showing http://localhost/insurancepolicydir instead of d:\insurancepolicydir – SaraDob Jan 11 '17 at 14:33
  • Please don't throw your code in a comment. You can [edit] (<= LOOK! It's a link! Click on it!) your question at any time to improve it. It looks like you haven't debugged your code. Simply walking through it while executing would tell you that `str = policyNo;` is absolutely positively wrong. There's more going on here, so I still can't answer. But you need to stop guessing and debug. Stop whatever you are doing and read this https://msdn.microsoft.com/en-us/library/sc65sadd.aspx –  Jan 11 '17 at 15:03

0 Answers0