![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| Is it possible to create a folder outside the root? At the moment I use:- Code: Dim filepath as string = "~/documents/" & user.userref Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filepath) What I'd like to do is create a folder in:- Code: filepath = "../../documents/" user.userref Any ideas? |
| Sponsored Links |
|
#2
| ||||
| ||||
| Posting the exact error message is always helpful
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.Join our Folding team: DeveloperBarn Folding |
|
#3
| ||||
| ||||
| Error message is:- System.Web.HttpException: Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path) at System.Web.Util.UrlPath.Reduce(String path) at System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) at System.Web.VirtualPath.Combine(VirtualPath relativePath) at System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) at System.Web.HttpServerUtility.MapPath(String path) at xxxxxx.App.BLL.UsersBLL.AddUserDoc(UsersBOL user) in..... |
|
#4
| ||||
| ||||
| It appears to be an issue with IIS: http://support.microsoft.com/default...;en-us;Q226474 The above is for Classic ASP, but sounds like the same thing. |
|
#5
| ||||
| ||||
| I came up with this pseudo server.mappath. Code:
Namespace MyCompany.App.BLL
Public Class SiteBLL
Public Shared Function MapPath() as String
Dim filepath as string = string.empty
Dim x as array = split(HttpContext.Current.Server.MapPath("~/" , "\")
Dim i as integer = 0
Do until x(i) = "wwwroot"
filepath &= x(i) & "\"
i += 1
loop
Return filepath
End Function
End Class
End Namespace
Code: Imports MyCompany.App.BLL
.
.
.
.
Dim new_folder as String = "My Docs"
Dim filepath As String = SiteBLL.MapPath
If not string.IsNullOrEmpty(filepath) then
filepath &= "the_folder_you_want\" & new_folder
Try
Directory.CreateDirectory(filepath)
Catch ex as Exception
error_var = ex.Message.ToString
End Try
Else
error_var = "Could not locate directory"
End If
If you just write Server.MapPath("~/") to the screen, you'll see the path structure. This should account for any folder/drive/server changes provided the folder you want to stop at doesn't change. Obviously to access documents you'll need to repeat the process to build the filepath to use GetFiles etc. And you need to import the System.IO namespace into your page. Hope that helps someone... Last edited by richyrich; June 5th, 2008 at 01:18 AM. |
![]() |
|
| Bookmarks |
| Tags |
| create, directory, root |
| Thread Tools | |
| Display Modes | |
|
|