使用Web Api的相对路径

时间:2014-05-18 12:59:01

标签: c# path asp.net-web-api

我想要做的是通过我的网络Api发送图像。直到现在我使用绝对路径和方法Image.FromFile,然后我将图像转换为Base64,一切都工作正常。但是现在我上传了我的项目,除了图像之外一切正常,因为存储的路径是“C:............等”我试图使用像“Images / MyImage.png”这样的相对路径“或”/Images/MyImage.png“或”〜/ Images / MyImage.png“但没有任何效果。 我该如何解决这个问题?

PS 我的问题与这个问题相同:IIS virtual directory and ASP.NET directory paths但是没有一个解决方案适合我

非常感谢你 问候, 马可

1 个答案:

答案 0 :(得分:2)

你试过这个吗?

string root_path = HttpRuntime.AppDomainAppPath;
string image_folder_path = root_path+"images";
/// Use the path