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
.
My question is, how do I upload a picture to a relative path within my app hosted on Windows Azure? 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.
Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…