Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

Virtual File Path

Is there a .net method to convert a file path to a virual file path?

Example:

C:/somefile.pdf
convert to:
https://www.mysite.forms/somefile.pdf

Thank you
0
thenrich
Asked:
thenrich
  • 6
  • 3
  • 2
  • +1
2 Solutions
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
What do you you mean by convert?  is the file outside of the website?  If that is the case, you would use file system object http://msdn.microsoft.com/en-us/library/aa711216(v=vs.71).aspx  and copy the file to a folder inside of your webroot.
0
 
thenrichAuthor Commented:
The file is inside the website.
0
 
thenrichAuthor Commented:
My mistake. Convert file path to:

www.mysite.com/forms/somefile.pdf
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CodeCruiserCommented:
Can you explain the situation?

There is Server.MapPath which basically does the opposite of what you want but I have not seen a function for what you need.
0
 
thenrichAuthor Commented:
I want the site to serve up a file based on a file structure.

I can't explicitly embed a link as files change daily. I need the site to read the file structure. Similar to FileZilla.
0
 
CodeCruiserCommented:
Do you not know even the root folder path?

One option is to have a page which reads the file from disk and writes to client.
0
 
thenrichAuthor Commented:
I am using a treeview and emulating the structure just fine. My problem is the file itself. I have a directory in which FTP users write to a modify all the time. So even though I have a root there can be multiple levels to the file itself.
0
 
thenrichAuthor Commented:
I was hoping to us NavigateURL of the treeview and that's where I need the virtual path.
0
 
CodeCruiserCommented:
>I need the virtual path.

Virtual path is under the site directory. If this root of treeview is under your site path, you can get list of files and directories and construct the virtual path.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I do this on multiple sites.  All the file live in a folder c:\root\sites\website.com\files  and you want to list each file in the the files folder and display them to the site as a link.


http://www.4guysfromrolla.com/webtech/faq/FileSystemObject/faq5.shtml

This is in classic asp but I believe you can use fso in .net

im objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Get the folder object associated with the directory
Dim objFolder
Set objFolder = objFSO.GetFolder("c:\root\sites\website.com\files")

'Loop through the Files collection
Dim objFile
For Each objFile in objFolder.Files
 Response.Write  "<a href=""/files/"&objFile.Name &""">"&objFile.Name &"</a>""
Next

'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing

Open in new window

0
 
thenrichAuthor Commented:
Codecruiser,
Yea it looks like I'll have to do some 'string-smithing' to get what I want. Was hoping for a more elegant solution.

Padas,
I don't see a solution in your posting. I'm already emulating the file structure?
0
 
ArkCommented:
why not use base href + relative path?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now