Guy Assaf
Guy Assaf

Reputation: 991

Azure, App service, "The system cannot find the file specified"

Having an App in Azure app services. A .NET web project.

Running the line:

System.IO.File.ReadAllText("D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")

will throw an exception

The system cannot find the file specified.

you can see the file is there and believe me it is not miss spelling, locally it works fine and fail when deployed.

The file is in the correct path as you can see

Upvotes: 1

Views: 4228

Answers (2)

Guy Assaf
Guy Assaf

Reputation: 991

Well, the problem was in a different location in the code. The code as published works fine.

Upvotes: 0

Tom Sun
Tom Sun

Reputation: 24569

The code you mentioned need to be changed as following:

System.IO.File.ReadAllText(@"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")

You mentioned that will throw not found exception, it is very odd. The code should work in the azure website if the file is existing.

The system cannot find the file specified.

It seems that expection is caused by other codes. We also could remote debug the WebApp with Vistual Studio and we could get the more detail info about exception.

We also could add a sample test aspx page to test it. The following is my test steps.

1.Create a .net Web project and the index.aspx page

2.Add the code to index.aspx.CS file and index.aspx file

 protected void Page_Load(object sender, EventArgs e)
        {
          var file= System.IO.File.ReadAllText(@"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings");
            Label1.Text = file;
        } 

index.aspx

    <div>

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </div>

3.Publish the Website to azure environment and add the setting file with content "Test info" via the Kudu tool enter image description here

  1. Visit the index page from the browser and check that it works correctly.

enter image description here

Upvotes: 1

Related Questions