Reputation: 2076
Hello Code Experts, I am uploading some files to a virtual directory. For the virtual directory I am giving the path like
"/Uploads/" + DatabaseName + "/" + REOID + "/" + "ExternalDocument" + "/";
It works fine in my local but not in live server. It is not uploading files in live server.
If I change it to
"~/Uploads/" + DatabaseName + "/" + REOID + "/" + "ExternalDocument" + "/";
Then will it work? If not then how shall I map it to virtual directory?
Upvotes: 0
Views: 160
Reputation: 820
+1 to @MarkisT. Would suggest you also let the Framework do the combination for you:
http://msdn.microsoft.com/en-us/library/dd782933.aspx
using System.IO;
using System.Web;
var path = Path.Combine("~/Uploads", DataBaseName, REOID, "ExternalDocument");
var fullPath = Server.MapPath(path);
If you are still having issues; would suggest you inspect fullPath on local and server to understand what is happening as relates to virtual and absolute paths. You may also have security issues on the server, especially if you happen to be writing outside the application directory. Of course, would expect exceptions in that case.
Upvotes: 1
Reputation: 1813
use the Server.MapPath function
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
Server.MapPath("~/Uploads/" + DatabaseName + "/" + REOID + "/" + "ExternalDocument" + "/");
Upvotes: 2
Reputation: 62093
Read the documentation on waht the ~ means. You willfind ou tthe second approach is always valid, the first one not. Te first assuems the folder is /Uploads (at the web server root).
Upvotes: 1