Solved

Virtual File Path

Posted on 2013-05-18
12
453 Views
Last Modified: 2013-05-20
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
Comment
Question by:thenrich
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39177403
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
 
LVL 5

Author Comment

by:thenrich
ID: 39177439
The file is inside the website.
0
 
LVL 5

Author Comment

by:thenrich
ID: 39177441
My mistake. Convert file path to:

www.mysite.com/forms/somefile.pdf
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39177731
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
 
LVL 5

Author Comment

by:thenrich
ID: 39177745
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39177750
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

by:thenrich
ID: 39177756
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
 
LVL 5

Author Comment

by:thenrich
ID: 39177757
I was hoping to us NavigateURL of the treeview and that's where I need the virtual path.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 39177785
>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
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 250 total points
ID: 39177849
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
 
LVL 5

Author Comment

by:thenrich
ID: 39177898
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
 
LVL 27

Expert Comment

by:Ark
ID: 39183229
why not use base href + relative path?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now