开发者

Virtual Path Issue

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 开发者_JAVA百科work? If not then how shall I map it to virtual directory?


use the Server.MapPath function

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

Server.MapPath("~/Uploads/" + DatabaseName + "/" + REOID + "/" + "ExternalDocument" + "/");


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜