How do I get a list of files from a web directory?
This is an interesting topic that I researched recently. As you know, you can access BITS through COM, but here are some projects to make it easier:
SharpBITS.NET Formal design wrapper
with friendly background Intelligent Transfer Service (BITS)
This MSDN article might be a little more than you want to know.
I experimented with the code in the CodeProject link and it seems to work quite well. The CodePlex project looks very good, but I haven't tried it.
source to share
Ok, if the web server allows you to list the files in the directory in question, you can go.
Unfortunately, there is no standard on how the web server should return the list to you. It is common in HTML, but HTML is not always formatted on different web servers.
If you want to always download files from the same directory on the same web server, simply use the "view source" while in your web browser directory. Then try writing a small regex that will capture all filenames from the HTML source.
Then you can create a WebClient, query the directory url, parse the response to get the filenames with your regex, and then process the files with your BITS client
Hope it helps
source to share
private void ListFiles()
{
//get the user calling this page
Gaf.Bl.User userObj = base.User;
//get he debug directory of this user
string strDebugDir = userObj.UserSettings.DebugDir;
//construct the Directory Info directory
DirectoryInfo di = new DirectoryInfo(strDebugDir);
if (di.Exists == true)
{
//get the array of files for this
FileInfo[] rgFiles = di.GetFiles("*.html");
//create the list ... .it is easier to sort ...
List<FileInfo> listFileInfo = new List<FileInfo>(rgFiles);
//inline sort descending by file full path
listFileInfo.Sort((x, y) => string.Compare(y.FullName, x.FullName));
//now print the result
foreach (FileInfo fi in listFileInfo)
{
Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");
} //eof foreach
} //eof if dir exists
} //eof method
source to share