Noel
Noel

Reputation: 1

Unable to determine if a file is on a web server because the various methods of determining the directory do not work

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.

Upvotes: 0

Views: 203

Answers (2)

Bruce Zhang
Bruce Zhang

Reputation: 3042

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.

Upvotes: 0

persian-theme
persian-theme

Reputation: 6638

Try this code

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

Check if a file exists on the server

Upvotes: 2

Related Questions