Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Cannot use a leading .. to exit above the top directory" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old June 4th, 2008, 09:52 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default Cannot use a leading .. to exit above the top directory

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)
which is fine for creating within a sub folder of root.

What I'd like to do is create a folder in:-
Code:
filepath = "../../documents/" user.userref
but it gives an error saying I'm trying to create a folder outside the root.

Any ideas?
Reply With Quote
Sponsored Links
  #2  
Old June 4th, 2008, 10:03 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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
Reply With Quote
  #3  
Old June 4th, 2008, 10:10 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default Sorry J

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.....
Reply With Quote
  #4  
Old June 4th, 2008, 10:23 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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.
Reply With Quote
  #5  
Old June 5th, 2008, 01:02 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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
Within the Do Until loop you just have to change the value to what ever folder you want the path to stop at.

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.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Tags
create, directory, root

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 05:40 PM.



Content Relevant URLs by vBSEO 3.2.0