Reputation: 67
I searched around stackoverflow on how to make a relative file and have tried various things and it hasn't worked, and i was hoping to see if you guys could help me out.
here is my connection sting in my web.config file:
<add name="2007 Database 05-12-2013(Esfahanian's conflicted copy 2013-06-24)
ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" providerName="System.Data.OleDb"/>
and here relative path in my aspx
file:
<script runat="server">
string connectionString = ConfigurationManager
.ConnectionStrings["2007 Database
05-12-2013(Esfahanian's conflicted copy 2013-06-24) ConnectionString"]
.ConnectionString + Server.MapPath("..\..\Anderson\2007
Database 05-12-2011 (Esfahanian's conflicted copy 2013-06-24).mdb");
</script>
And I get this error: CS1009: Unrecognized escape sequence
So what exactly am I doing wrong
Upvotes: 0
Views: 1939
Reputation: 745
You aren't escaping the "\" character in your path so it is causing an error in the MapPath()
method.
Change this:
Server.MapPath("..\..\Anderson\2007 Database 05-12-2011 (Esfahanian's conflicted copy 2013-06-24).mdb"
to this:
Server.MapPath(@"..\..\Anderson\2007 Database 05-12-2011 (Esfahanian's conflicted copy 2013-06-24).mdb"
or this:
Server.MapPath("..\\..\\Anderson\\2007 Database 05-12-2011 (Esfahanian's conflicted copy 2013-06-24).mdb"
Upvotes: 1
Reputation: 144
You are using \ in your path string but thats the symbol for literal. So any char following the \ will be inturpreted as a literal like \. is not a valid char. You actualy want the literal \ the sequence for which is \\ Also @ infront of a string tells that you dont want literals.
So mappath(" needs to be mappath(@" or every \ needs to become \\
Upvotes: 0