Uploading image to a targeted path

Hobbes

Active member
Joined
May 22, 2003
Messages
37
I am trying to upload an image to a targeted folder.
(i.e. C:\Inetpub\wwwroot\Store\images\)

But my file upload page is in another folder.
(i.e. C:\Inetpub\wwwroot\Store\admin\)

I use the following code:

Code:
Dim strFilePath As String
strFilePath = System.IO.Path.GetDirectoryName(Server.MapPath("uploadFile.aspx"))

uploadFilePath.PostedFile.SaveAs((strFilePath & "\" & "images" & "\" & txtFileName.Value))

lblTitle.InnerHtml = "File uploaded successfully"

lblMessage.InnerHtml = "Your file was uploaded successfully to <br>" & _
 "<b>" & strFilePath & "\" & _
 txtFileName.Value & "</b><br>on the Web server."

 HideFileUploadControls()
 HideUserAuthenticationControls()
 lblMessage.Visible = True
 btnReUpload.Visible = True

HyperLink1.NavigateUrl = "http://localhost/store/images/" & txtFileName.Value
HyperLink1.Visible = True
The thing is that using
System.IO.Path.GetDirectoryName(Server.MapPath("uploadFile.aspx"))
I am uploading it to
"C:\Inetpub\wwwroot\Store\admin\"

Any one have any idea to load it into my desired folder??

Thanks

:)
 
Last edited by a moderator:
Append a ".." to the file name, and it will be smart enough to
back up one directory, like so:

"C:\Inetpub\wwwroot\Store\admin\..\images\"
 
Back
Top