Connecting Tech Pros Worldwide Forums | Help | Site Map

file path ?

Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#1: Apr 2 '09
i have a file uploaded to my server
the path is shown as
E:\abc\def\upload\contents.doc

to download it the path should be

http://3.212/232/abc/def/upload/contents.doc

how do i go about it ?
i am saving the file by using
Expand|Select|Wrap|Line Numbers
  1.  o.FileFullPath = Server.MapPath(".") & "\upload\"  & sFile 
from a script i downloaded

jenkinsloveschicken's Avatar
Member
 
Join Date: Dec 2006
Posts: 56
#2: Apr 4 '09

re: file path ?


aashishn86,

So is your question how do you go about making an href to point to the file? Or are you trying to save the file name with the www address of the file?

I would suggest that if you are getting the file path and it is correct, then in your output page, you could perform a split on the file path on ":" and then append your www address prefix.

For example:

Expand|Select|Wrap|Line Numbers
  1. '''Using static sFile value for demonstration purposes
  2. sFile = "contents.doc"
  3.  
  4. '''Get server file path
  5. str_fullPath = Server.MapPath(".") & "\upload\"  & sFile
  6.  
  7. '''Set the www prefix
  8. str_httpPath = "http://3.212/232"
  9.  
  10. '''Remove localhost routing portion of the file path returned from Server.MapPath
  11. '''First line creates a two value array, the local host portion is the 0 index and we
  12. '''don't want that, so we use the 1 index of the str_httpPathProc array created by
  13. '''the Split function
  14. str_httpPathProc = split(str_fullPath,":")
  15.  
  16. '''Correct slash direction for www routing
  17. str_httpPathProc1 = Replace(str_httpPathProc(1),"\","/")
  18.  
  19. '''Concatenate the www prefix the with processed file path
  20. str_httpPath = str_httpPath & str_httpPathProc1
  21.  
  22. '''Write out our new file path. You can use this path as the href value to create
  23. '''links to files on the server
  24. Response.write str_httpPath
  25.  
  26.  
Hope that's what you were after. There are more complex methods, but this should get your started.


Best Regards,
Jenkins
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#3: Apr 5 '09

re: file path ?


Quote:

Originally Posted by jenkinsloveschicken View Post

aashishn86,

So is your question how do you go about making an href to point to the file? Or are you trying to save the file name with the www address of the file?

I would suggest that if you are getting the file path and it is correct, then in your output page, you could perform a split on the file path on ":" and then append your www address prefix.

For example:

Expand|Select|Wrap|Line Numbers
  1. '''Using static sFile value for demonstration purposes
  2. sFile = "contents.doc"
  3.  
  4. '''Get server file path
  5. str_fullPath = Server.MapPath(".") & "\upload\"  & sFile
  6.  
  7. '''Set the www prefix
  8. str_httpPath = "http://3.212/232"
  9.  
  10. '''Remove localhost routing portion of the file path returned from Server.MapPath
  11. '''First line creates a two value array, the local host portion is the 0 index and we
  12. '''don't want that, so we use the 1 index of the str_httpPathProc array created by
  13. '''the Split function
  14. str_httpPathProc = split(str_fullPath,":")
  15.  
  16. '''Correct slash direction for www routing
  17. str_httpPathProc1 = Replace(str_httpPathProc(1),"\","/")
  18.  
  19. '''Concatenate the www prefix the with processed file path
  20. str_httpPath = str_httpPath & str_httpPathProc1
  21.  
  22. '''Write out our new file path. You can use this path as the href value to create
  23. '''links to files on the server
  24. Response.write str_httpPath
  25.  
  26.  
Hope that's what you were after. There are more complex methods, but this should get your started.


Best Regards,
Jenkins

that seems to solve my problem
but what if the server on which the site is hosted changes on a later date...
once the development is over. the server is likely to be changed...
i need a permanent solution...
would getting the server ip from Server.variables be okay ?
jenkinsloveschicken's Avatar
Member
 
Join Date: Dec 2006
Posts: 56
#4: Apr 5 '09

re: file path ?


I would imagine that would work as long as the users can hit the IP from a remote machine(no proxy, etc). You can always try it and use the concatenation to build the hrefs.

Let me know if that works for you.

Cheers,
Jenkins
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#5: Apr 6 '09

re: file path ?


Quote:

Originally Posted by jenkinsloveschicken View Post

I would imagine that would work as long as the users can hit the IP from a remote machine(no proxy, etc). You can always try it and use the concatenation to build the hrefs.

Let me know if that works for you.

Cheers,
Jenkins

Hi !!
that works fine for me... except for two problems
1) a text file opens in the browser itself when i click the link . I want it to be downlaoded
2) for filenames which have spaces , the name after the space is truncated, so the link doesn't open.....
jenkinsloveschicken's Avatar
Member
 
Join Date: Dec 2006
Posts: 56
#6: Apr 8 '09

re: file path ?


In response to your inquiries:

1. Can you provide a sample link? Chancing a guess, it may be browser related(such as server MIME types).

2. Check out this old post:

http://bytes.com/groups/asp/126721-u...rver-urlencode

This post talks expressly about the issues encountered when created hrefs to file names with spaces.


Hope this helps

Cheers,
Jenkins
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#7: Apr 9 '09

re: file path ?


hey
just putting the link in double quotes solved the problem...
thanks...
Reply