当我尝试使用下一个代码运行.aspx页面时:
System.IO.File.Delete("~/img/afisha/" + fileName);
它写了一条消息:“无法找到路径的一部分'C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \〜\ img \ afisha \ brs_01.jpg'。” 但我需要使用相对路径。
PS。连接字符串也是如此:<add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>
有什么想法吗? (它会在服务器上正常工作吗?)
答案 0 :(得分:3)
尝试Server.MapPath()
System.IO.File.Delete(Server.MapPath("~/img/afisha/" + fileName));
对于连接字符串,您可以尝试使用变量字符串
internal readonly string CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Persist Security Info=False;"
internal static string ConnectionString
{
get
{
return string.Format(CONNECTION_STRING,
Server.MapPath("~/ExpertBase.mdb"));
}
}