views:

35

answers:

1

When I try to run .aspx page with next code:

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'." But I need to use relative path.

ps. the same shit is 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>

Any ideas? (and will it work on the server properlly?)

+3  A: 

Try 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")); 
    } 
}
hunter
And what about connection string?
Raigomaru
looks like you need to use the full path for a mdb connectionstring (c:\inetpub...)
hunter
you can probably use a global ConnectionString variable rather than the connectionstring from the .config, which will suck slightly since the web.config is so simple.
hunter