I'm using a server component to grab screenshots and save them to the server. I'd like to save them in a directory that is one level up from the current website. So, for example, the website is at c:\inetpub\wwwroot\website and the directory I want to save images in is c:\inetpub\wwwroot\screenshots. I've tried using this in my code to set the save directory: Server.MapPath("..") + "\\screenshots\\" but I get an error saying it failed to map the path to "/.". Is this even possible? If not, what is the "Enable parent paths" in IIS for? I have enabled that, by the way... Is it possible, what am I doing wrong? Also, could I set the directory lower in the path (i.e. c:\screenshots)?
Thanks for the help!
Eddie
Hi Eddie,
try with this code
Path.Combine(Directory.GetParent(Server.MapPath("")).FullName, "screenshots")
With Server.MapPath you get your root folder, then with Directory.GetParent you get the root folder parent and finally you combine that with the "screenshot" folder using Path.Combine.
I hope it helps.
Regards,
Fernando
You can also use Server.MapPath("~") to resolve to the application root path. This may not be the same as root "/", but it may serve the same or better purpose for the original question, since I'd imagine a screenshots directory would be hanging off the application root directory.
correct syntax with parent path:
Server.MapPath("../screenshots")without parent path:
Server.MapPath("~/screenshots")
Thanks, that solution worked for me. I tried the others suggested here but they didn't work for me.
Thanks!
eddie
Cheers, glad I could help and hope you now understandwhy this work.
Actually, it wasFerVitale's answer that worked for me. The two options you suggested returned errors in my code... but thanks for replying!
eddie
What error did you get using the code I gave??
Failed to map path '/.'
Eddie
Shadow Wizard:
correct syntax with parent path:
Server.MapPath("../screenshots")without parent path:
Server.MapPath("~/screenshots")
I got Shadow Wizard's method to work just fine. Thanks!
0 comments:
Post a Comment