Last post Jun 05, 2007 07:42 AM by OWScott
Jun 04, 2007 03:03 AM|Hermz|LINK
i have three different websites on a server located in different directories under the wwwroot of the server.i have to upload images from one .aspx upload file to three images folders found on each website...i have used the following code in the codebehind
file to upload the images:
Dim Loop1 As Integer
Dim myPicPath As String
Dim MyFileCollection As HttpFileCollection = Request.Files
'lblError.Text = "Path is: " + Server.MapPath("../images/d3/banners/" & banner)
'lblError.Visible = True
For Loop1 = 0 To MyFileCollection.Count - 1
myPicPath = Server.MapPath("../images/show_pictures/" & fileName)
' Save the file to 1st directory.
'myPicPath = Server.MapPath("../../d1/pictures/" & fileName)
'Save the file to 2nd directory.
'myPicPath = Server.MapPath("../../d2/pictures" & fileName)
'Save the file to 3rd directory.
but when running the page it gives me an error:" cannot use leading .. to exit the above top directory"..
anyone can help...
PLEASE ITS SOOOOO IMPORTANT
Jun 04, 2007 05:34 AM|Sohnee|LINK
This would be a security feature - to upload to a directory that isn't part of your application, you would need to set it up as a share.
Jun 04, 2007 07:25 AM|Hermz|LINK
but how do we set up the share??????
can u help me out...
Jun 04, 2007 07:36 AM|HostingASPNet|LINK
This is not very elegant solution...the solution depends of your server access.
You could try also to configure your websites to use only one image folder, or to import all images in one database...
Jun 04, 2007 08:24 AM|Hermz|LINK
sorry but this solution is not aplicable coz ill have to change many webpages and paths and that would make a messy result ..its gonna make me crazyy...the other websites are made using classic asp platform and i didnt face this problem..only with asp.net
m facing that..so i dont think that its is really a security or permissions issue...any other idea...!!!!!!!!!
Jun 04, 2007 10:11 AM|Sohnee|LINK
Can you save the file using the full UNC path - this would test whether it is a permissions issue. For example... c:\inetpub\wwwroot\website2\images\ rather than asking the server to map the path.
If it works when you do that, you are right about the permissions issue and we'll need to give you a better answer.
Jun 04, 2007 10:26 AM|Hermz|LINK
i have tried that but i recieved an error saying that i must use the virtual path...
so wat wud it b....
Jun 04, 2007 01:31 PM|OWScott|LINK
Since you are working outside of your website structure, you must use a physical path. A UNC path isn't needed in this situation unless you are working off of the local disks. So, just put in an actual physical path and you should be set.
The reason you can't go above your site root is that there isn't a concept of "up a folder" from the root of your site. Your site could be a physical path or UNC path and the structure can be made up of many virtual directories with any structure you create.
So IIS can't safely assume the /../ is one physical folder up from the root of the site. The website root is as far up as it goes.
Jun 05, 2007 01:44 AM|Hermz|LINK
i have tried using the virtual path of the folder to where i want to save the images(the folder outside the root directory of my asp.net application) but the browser gave me an error saying that i must use a virtual path only.....but why the "../../" can't
Jun 05, 2007 07:42 AM|OWScott|LINK
This wouldn't have worked in Classic ASP either unless you started with the *physical* path and went up a folder from that.
You need to do everything using physical folders, and not virtual paths. For example, use Server.MapPath to get the path for "/". Then, not using MapPath anymore, move up a folder from that, then move into the images/show_pictures folder.
You cannot do all of that within the MapPath method.