簡體   English   中英

程序使用Microsoft Visual Studio文件夾而不是相對路徑

[英]Program uses Microsoft Visual Studio folder instead of relative path

當我嘗試使用下一個代碼運行.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> <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>

有任何想法嗎? (它將在服務器上正常運行嗎?)

試試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")); 
    } 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM