I have an ASP.NET MVC 4 app that i want to deploy to Windows Azure. A part of this app involves uploading a picture. When the picture is uploaded, I want to store the picture in a directory located at /pictures/uploaded.
Up to this point, my app has been hosted in a Virtual Machine. I was able to do the above by using the following:
string path = ConfigurationManager.AppSettings["rootWebDirectory"] + "/pictures/uploaded;
// Get the file path
if (Directory.Exists(path) == false)
Directory.CreateDirectory(path);
string filePath = path + "/uploaded" + DateTime.UtcNow.Milliseconds + ".png";
filePath = filePath.Replace("/", "\\").Replace("\\\\", "\\");
// Write the picture to the file system
byte[] bytes = GetPictureBytes();
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
{
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Flush();
fileStream.Close();
}
Currently, ConfigurationManager.AppSettings["rootWebDirectory"] points to an absolute path. I belive this is where my problem lies. I can't figure out how to switch all of this to a relative path. How do I upload a picture to a relative path within my app hosted on Windows Azure?