TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kevin Pickett
NA
1
4.1k
How do I list files from a url directory into a listview.
Mar 21 2014 4:25 PM
I wrote a simple program in VS 2013 C# to compare files on desktop to files in a web directory.
I am listing the local files in a textbox and want to list the remote files in a textlist with checkboxes. Then place a check next to the files in the textlist so I can then click a button to download them.
It is giving me an Object reference error when trying to add the items from regex to the textlist.
----- Current portion of Windows Forms Code =====
public static string GetDirectoryListingRegexForUrl(string url)
// get the files in the url directory and list in the textlist
{
if (url.Equals("http://website/subfolder/"))
{
return ""<a href=\".*\">(?<name>.*)</a>";
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string html = reader.ReadToEnd();
Regex regex = new Regex(GetDirectoryListingRegexForUrl(url));
MatchCollection files = regex.Matches(html);
if (files.Count > 0)
{
foreach (Match files in matches)
{
TextList.Items.Add(files.Groups[1]);
}
throw new NotSupportedException();
}
}
}
}
----------
I have created the textlist in the design phase, I am able to add items to the list in the design window so I believe the textlist is already referenced as an object?
Is this the correct way to do this or is their an easier method. This is one part of many in my forms application.
thanks
Reply
Answers (
0
)
How retrive id & password from .txt file
how to run a cs file other than program.cs in consoleappln