netDeveloperUK
netDeveloperUK

Reputation: 39

File.Exists fails on Azure Website

I am deploying my website to an Azure website. I need to work with a special file type in code behind and this work on my development machine but when I deploy to Azure it can't find the file?

var real_File = HttpContext.Current.Server.MapPath("~/FolderName/Filename.w00");
if (File.Exists(real_file))
{
     lblStatus.Text = "File exists.";
}
else
{
     lblStatus.Text = "File could not be found.";
}

Is there something I must configure in Azure to get this to work?

Upvotes: 0

Views: 527

Answers (1)

Adrian
Adrian

Reputation: 251

Is the file in your VS solution? If so, have you set the "Copy Always" attribute on the file?

This could be a problem with your current directory (Environment.CurrentDirectory) being different on your development environment. I would build a full path to the file based on where you actually think it is, not just the relative path to the current directory. If you know it's in the same directory as your deployed assemblies, you can use Assembly.GetExecutingAssembly().Location.

Also, logging may help you here.

Upvotes: 1

Related Questions