[英]Program uses Microsoft Visual Studio folder instead of relative path
When I try to run .aspx page with next code: 当我尝试使用下一个代码运行.aspx页面时:
System.IO.File.Delete("~/img/afisha/" + fileName);
it writes a message: "Could not find a part of the path 'C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\~\\img\\afisha\\brs_01.jpg'." 它会写一条消息:“找不到路径'C:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ Common7 \\ IDE \\〜\\ img \\ afisha \\ brs_01.jpg'的一部分。” But I need to use relative path. 但是我需要使用相对路径。
ps. PS。 the same thing happens with the connection string: <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>
连接字符串会发生相同的事情: <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>
<add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>
Any ideas? 有任何想法吗? (and will it work on the server properlly?) (它将在服务器上正常运行吗?)
Try Server.MapPath()
试试Server.MapPath()
System.IO.File.Delete(Server.MapPath("~/img/afisha/" + fileName));
for the connection string you can try using a variable string instead 对于连接字符串,您可以尝试使用变量字符串代替
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"));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.