0

I am developing an application in asp.net, vs2015 using c# and the development environment is a Win10Pro machine. I can use any of the various methods to obtain the working directory and see if a particular file exists on the dev pc, but not on the Web Server. I have tried the methods laid out on: Get current application physical path within Application_Start

All work on the Dev PC, but when used on the Web Server it will not return the working directory. The Server is a 2016 Data server using IIS10. The issue is that the web site I am putting together work fine, except to display GrapeCity ActiveReports reports AR15. The web page containing their web viewer opens just fine and is looking for a report file (MyReport.rdlx). The global.aspx file is pointing to the root directory but when the web viewer opens up, it says File Not Found. I have absolutely no idea and tech support is not sure. Is this an IIS issue that is preventing the code to locate and verify the file is there? Any direction would be much appreciated. This has been very frustrating and time consuming. AppDomain.CurrentDomain.BaseDirectory does not work, HttpRuntime.AppDomainAppPath does not as well as all the others. The request comes back blank.

string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() +"SPU01_Dates.rdlx";
if (File.Exists(filename))
{
    Response.Write("YES");
}
else
{

    Response.Write("NO");
    Response.Write("</br");
    Response.Write(filename);
}

All this just returns nothing.

Thanks.

NetMage
  • 26,163
  • 3
  • 34
  • 55
Noel
  • 1
  • I hope it returns `NO` with a broken `br` tag and the `filename`. – NetMage Jan 20 '21 at 20:45
  • Thank you all for your comments. I found the answer. The page on which I was trying to map the directory and file was not using a web page that contained the site's masterpage. As soon as I recreated the page as a content page, it worked. Again Thank you all. – Noel Jan 21 '21 at 16:30

2 Answers2

2

Try this code

if (File.Exists(Server.MapPath(filename)))

Check if a file exists on the server

Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17
0

In my test, it returned YES and worked well. Did you put "SPU01_Dates.rdlx" file in root folder?

In the development environment, it returned YES, and when I deployed it to IIS, it returned NO. I found that during the deployment process, the rdlx file was not deployed with the project, so I recreated one in the deployed folder, and it returned YES.

The test proves that AppDomain.CurrentDomain.BaseDirectory is the most accurate way to get the file path. When you test this code in IIS, does it return NO or empty? Returning empty means that this piece of code has not been executed.

Bruce Zhang
  • 2,880
  • 1
  • 5
  • 11