I need to check if a file exists and I have put this together:
File.Exists(Server.MapPath("/img/" + objMySqlDataReader["imagename"].ToString() +".png"))
I would l like to know if there's another way to get the filepath instead of using Server.MapPath because I've heard Server is really slow and you should avoid using it (for example I use HttpUtility instead for HtmlEncode).
Hi,
You can try to useRequest.PhysicalApplicationPath. This property returns the physical path of the root directory of your web application. Then append the folder name and the filename to it and that should work fine.
Hope this helps to solve your problem
Good Luck
Regards
Vineed
You can supply the full file system path instead.
vineed_menon Thank you,Request.PhysicalApplicationPath seems to be working fine.
Mikesdotnetting Do you mean manually writing C:\xxx\xx? If so, it's not safe enough because I'm on a webhotel hosting.
Saturday3AM:
Mikesdotnetting Do you mean manually writing C:\xxx\xx? If so, it's not safe enough because I'm on a webhotel hosting.
Yes, that's what I meant. It's the quickest method by far, but clearly is not suitable if the filesystem path is likely to change.
Incidentally, where did you hear that Server.method is slow?
Not sure where I read it before but I googled it now and found this:http://www.msdner.com/forum/thread313324.html
Might be arguable.
Saturday3AM:
Not sure where I read it before but I googled it now and found this:http://www.msdner.com/forum/thread313324.html
Might be arguable.
Ah. I see what you mean. That hardly supports the theory that methods of the Server class are slow inherently.
0 comments:
Post a Comment