Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
 Server.MapPath("/Uploads/CrystalReport1.rpt")

Server.MapPath("~/Uploads/CrystalReport1.rpt")

Returning address without \
D:WEBDATAmydomain.comUploadsCrystalReport1.rpt

But i expected
D:\WEBDATA\mydomain.com\Uploads\CrystalReport1.rpt
Posted
Updated 7-May-13 4:54am
v2
Comments
Johnny J. 7-May-13 10:57am    
C# or VB? If it's C#, you might need to include an @:
Server.MapPath(@"/Uploads/CrystalReport1.rpt")
Server.MapPath(@"~/Uploads/CrystalReport1.rpt")
???

1 solution

This is not the API Server.MapPath gives you wrong string, but your observation is wrong. It always works correctly. Run it under the debugger or log this string to see.

—SA
 
Share this answer
 
Comments
JYOTIRMOY SAMANTA 7-May-13 11:04am    
Dim reportpath As String = Server.MapPath("/Uploads/CrystalReport1.rpt")
Dim reportpath2 As String = Server.MapPath("~/Uploads/CrystalReport1.rpt")
Then I am printing it with javascript

Response.Write("<script>alert('1 " & reportpath & "');</script>")
Response.Write("<script>alert('2 " & reportpath & "');</script>")
messagebox showing address without backslash
Sergey Alexandrovich Kryukov 7-May-13 11:12am    
Path string is correct, your output is not.
—SA
JYOTIRMOY SAMANTA 7-May-13 11:19am    
Another Important thing when I am assigning the reportpath to text property of label control it is showing correct path.
Me.Label1.Text = reportpath

and when I am checking if the file exist in that address it is returning not exist although it exists there.

If Not File.Exists(reportpath) Then
Response.Write("<script>alert('FILE ADDRESS WRONG');</script>")
Exit Sub
End If
Sergey Alexandrovich Kryukov 7-May-13 11:24am    
And this is because the file does not exist. Are you sure you know the right path? On server side?
After all, can you use the debugger and sort it all out?
—SA
JYOTIRMOY SAMANTA 7-May-13 11:31am    
I have used FileZilla FTP Client and checked that the file exists there in Uploads directory under the root and CrystalReport1.rpt file exist there in the Uploads directory. and physical address before my domain name D:\WEBDATA\ is returning by server.mappath

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900