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 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>

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

1 Answer 1

3

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")); 
    } 
}
Sign up to request clarification or add additional context in comments.

3 Comments

And what about connection string?
looks like you need to use the full path for a mdb connectionstring (c:\inetpub...)
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.