2010-08-10 68 views
1

,當我試圖運行與下面的代碼.aspx頁:程序使用Microsoft Visual Studio的文件夾,而不是相對路徑

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>

任何想法? (並會在服務器上運行properlly?)

回答

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

又是怎麼回事連接字符串? – 2010-08-10 23:48:48

+0

看起來像你需要使用mdb連接字符串的完整路徑(c:\ inetpub ...) – hunter 2010-08-10 23:49:59

+0

你可能可以使用全局ConnectionString變量而不是來自.config的連接字符串,這將自web.config稍微吸取非常簡單。 – hunter 2010-08-10 23:51:15

相關問題