Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
string[] files = Directory.GetFiles(@"\LeadImage\Pending\", "*.jpg", SearchOption.AllDirectories);


How to give URL path on server to access files from folder.

I have ADMIN folder on root and inside have web-pages and Folder "LeadImage" contains Folder "Pending"?
Posted
Updated 14-Nov-11 3:01am
v3

1 solution

So you want to make a list of absolute URLs, like:

ftp://example.com/LeadImage/Pending/file1.jpg
ftp://example.com/LeadImage/Pending/file2.jpg
ftp://example.com/LeadImage/Pending/file3.jpg

??

using System.Linq;
using System.Text.RegularExpressions;

string[] files = Directory.GetFiles(@"\LeadImage\Pending\", "*.jpg", SearchOption.AllDirectories);
var URLs = from file in files
           let f = file.Replace(@"\", "/")  // convert backslashes to forward slashes
           select Regex.Replace(f, @"(^.+)(/LeadImage/Pending/.+)$)", "ftp://example.com$2");  // strip all but subdirectory/file and rewrite as URL
 
Share this answer
 
v3
Comments
JawadHafiz 14-Nov-11 12:02pm    
Server Error in '/' Application.

Could not find a part of the path 'C:\LeadImage\Pending'.

thats not working
Cant help? Sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900