I get this error when I try to add items to an array, it adds with no problem 1 items, but when there are more it stops and gives an error.
nullReferenceException
Object reference not set to an instance of an object.
public void btnZoek_Click(object sender, EventArgs e)
{
if (search == false)
{
OpenFiles[index] = new AddFileClass();
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Application.StartupPath + "\\Saves");
System.IO.FileInfo[] rgFiles = di.GetFiles("*.txt");//add only .txt files
foreach (System.IO.FileInfo fi in rgFiles)
{
OpenFiles[index].setNewItem(index, fi.Name, Convert.ToString(di));//send the info to the array (Number, filename, filelocation)
index++;
}
search = true; //make sure it doens'nt add something double
}
if (search == true)
{
Form3_Zoeken_ frmSearch = new Form3_Zoeken_();
frmSearch.Show();
}
}
here is a pic to show that the fi(FileInfo) and di(DirectoryInfo) are not empty:
It looks to me that you never initialize the OpenFiles array items - that is, you only initialize the first item.
Try this:
public void btnZoek_Click(object sender, EventArgs e)
{
if (search == false)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Application.StartupPath + "\\Saves");
System.IO.FileInfo[] rgFiles = di.GetFiles("*.txt");//add only .txt files
foreach (System.IO.FileInfo fi in rgFiles)
{
OpenFiles[index] = new AddFileClass();
OpenFiles[index].setNewItem(index, fi.Name, Convert.ToString(di));//send the info to the array (Number, filename, filelocation)
index++;
}
search = true; //make sure it doens'nt add something double
}
if (search == true)
{
Form3_Zoeken_ frmSearch = new Form3_Zoeken_();
frmSearch.Show();
}
}
Related
I create a playlist for media player.
Follow my code:
Xaml:
<MediaElement x:Name="mePlayer" Margin="64,0,90,61" ></MediaElement>
<ListBox x:Name="listbox4" Background="Salmon" BorderBrush="Black" BorderThickness="3" Drop="listbox4_Drop" >
</ListBox>
<Button x:Name="load" Content="Load" HorizontalAlignment="Left" VerticalAlignment="Top" Width="76" Click="load_Click" Margin="184,285,0,0"/>
Xaml.cs:
private Dictionary<string, string> fileDictionary = new Dictionary<string, string>();
private void load_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
ofd.DefaultExt = ".mp3";
ofd.Filter = "All|*.*";
ofd.Multiselect = true;
Nullable<bool> result = ofd.ShowDialog();
if (result == true)
{
for (int i = 0; i < ofd.FileNames.Length; i++)
{
var filePath = ofd.FileNames[i];
var fileName = System.IO.Path.GetFileName(filePath);
fileDictionary.Add(fileName, filePath);
listbox4.Items.Add(fileName);
listbox4.SelectedItem = fileName;
}
}
}
private void listbox4_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (string droppedFilePath in droppedFilePaths)
{
for (int i = 0; i < droppedFilePaths.Length; i++)
{
var filePath = droppedFilePaths[i];
var fileName = System.IO.Path.GetFileName(filePath);
fileDictionary.Add(fileName, filePath);
listbox4.Items.Add(fileName);
listbox4.SelectedItem = fileName;
}
}
}
}
It's working single file drop but while I drop multiple file then it's not added on listbox.
Multiple loaded file is loaded but multiple file will not dropped.
How can I drop multiple file on listbox?
Since I am not able to replicate the problem you listed I currently can not help you in that regard. Though, I can help you where I see fit.
Your current Drop method has an extra loop that multiples the number of items you add to the listbox.
Your current method:
private void listbox4_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (string droppedFilePath in droppedFilePaths)
{
//if you keep this loop, you will all the dropped files for each dropped file
//therefore, if I dropped 3 files, I'd get 9 entries in the listbox
//if I dropped 4 files, I'd get 16 entries and so on...
for (int i = 0; i < droppedFilePaths.Length; i++)//this has to go
{//this has to go
var filePath = droppedFilePaths[i];//this needs to be a different variable since "i" will no longer exist
var fileName = System.IO.Path.GetFileName(filePath);
//fileDictionary.Add(fileName, filePath);
listbox4.Items.Add(fileName);
listbox4.SelectedItem = fileName;
}//this has to go
}
}
}
Refactored (using the ForEach)
private void blaze_125_listbox4_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (string droppedFilePath in droppedFilePaths)
{
var filePath = droppedFilePath;
var fileName = System.IO.Path.GetFileName(filePath);
//fileDictionary.Add(fileName, filePath);
listbox4.Items.Add(fileName);
listbox4.SelectedItem = fileName;
}
}
}
This would also work (using the ForLoop)
private void blaze_125_listbox4_Drop_anotherSpin(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
for (int i = 0; i < droppedFilePaths.Length; i++)
{
var filePath = droppedFilePaths[i];
var fileName = System.IO.Path.GetFileName(filePath);
//fileDictionary.Add(fileName, filePath);
listbox4.Items.Add(fileName);
listbox4.SelectedItem = fileName;
}
}
}
Slimmer
private void blaze_125_listbox4_Drop_Slimmer(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (string droppedFilePath in droppedFilePaths)
{
listbox4.Items.Add(System.IO.Path.GetFileName(droppedFilePath));
}
}
}
Using the dictionary to store items, and to update the list
Dictionary<string, string> fileDictionary = new Dictionary<string, string>();
private void blaze_125_listbox4_Drop_Slimmer(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] droppedFilePaths =
e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (string droppedFilePath in droppedFilePaths)
{
//listbox4.Items.Add(System.IO.Path.GetFileName(droppedFilePath));//don't need this anymore
//Check if the file is already in the dictionary.
//Check by looking up the key, and by looking up the value too.
if (fileDictionary.ContainsKey(System.IO.Path.GetFileName(droppedFilePath)) || fileDictionary.ContainsValue(droppedFilePath))
{
//no need to add this file, it's already in the dictionary
//if you try to add a file with a KEY identical to a KEY that already exists in the dictionary,
//it will throw an exception
//A dictionary can contain the same value multiple times, but it can not contain the same key more than once.
}
else
{
//the file is not listed in the dictionary, so lets add it
fileDictionary.Add(System.IO.Path.GetFileName(droppedFilePath), droppedFilePath);
}
}
}
//Now lets call the method in charge of updating the listbox
UpdateTheListbox(fileDictionary, listbox4);
}
private void UpdateTheListbox(Dictionary<string, string> incomingDictionary, ListBox listboxToModify)
{
listboxToModify.Items.Clear();//clear all the items in the list
foreach (KeyValuePair<string, string> item in incomingDictionary)
{
listboxToModify.Items.Add(item.Key);
}
//this method should probably be optimized because if your listBox already contains a large number of items
//it may be quicker to only add the missing items, instead of reverting back to an empty list, and adding all the items to it again.
//Though I'll leave this up to you to implement. We'll be here to answer questions if you have a hard time doing it.
}
Updated method to maintain the selected item if there is a selected item
private void UpdateTheListboxMaintainExistingSelection(Dictionary<string, string> incomingDictionary, ListBox listboxToModify)
{
var preSelectedItem = listboxToModify.SelectedItem;//store the current selection
listboxToModify.Items.Clear();//clear all the items in the list
foreach (KeyValuePair<string, string> item in incomingDictionary)
{
listboxToModify.Items.Add(item.Key);
}
//this method should probably be optimized because if your listBox already contains a large number of items
//it may be quicker to only add the missing items, instead of reverting back to an empty list, and adding all the items to it again.
//Though I'll leave this up to you to implement. We'll be here to answer questions if you have a hard time doing it.
//Maintain the selected item if there was one
if (preSelectedItem != null)
{
listboxToModify.SelectedItem = preSelectedItem;
}
}
To maintain the selection or select the last item if there was no selection
private void UpdateTheListboxMaintainExistingOrSelectLastAdded(Dictionary<string, string> incomingDictionary, ListBox listboxToModify)
{
var preSelectedItem = listboxToModify.SelectedItem;//store the current selection
listboxToModify.Items.Clear();//clear all the items in the list
foreach (KeyValuePair<string, string> item in incomingDictionary)
{
listboxToModify.Items.Add(item.Key);
}
//this method should probably be optimized because if your listBox already contains a large number of items
//it may be quicker to only add the missing items, instead of reverting back to an empty list, and adding all the items to it again.
//Though I'll leave this up to you to implement. We'll be here to answer questions if you have a hard time doing it.
if (preSelectedItem != null)
{
//Maintain the selected item if there was one
listboxToModify.SelectedItem = preSelectedItem;
}
else
{
//select the last item in the listbox if nothing was pre-selected
listboxToModify.SelectedItem = listboxToModify.Items[listboxToModify.Items.Count - 1];
}
}
I have this in my designer:
On the right is the files in a listView1.
On the left is the directory main directory of this files treeView1.
I have this code in menu strip item clicked event :
void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Upload")
{
List<String> selected = new List<String>();
foreach (ListViewItem lvi in listView1.SelectedItems)
{
selected.Add(lvi.Text);
}
AllFiles = selected.ToArray();
Bgw.RunWorkerAsync();
}
}
The problem is that the file/s in AllFiles array are only the filenames for example: bootmgr or install.exe
But i need that in the All Files each file will have also it's full path for example:
c:\bootmgr or c:\install.exe or c:\test\test\example.txt
How can i add to AllFiles also the paths ?
I tried now:
void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Upload")
{
List<String> selected = new List<String>();
string dir = treeView1.SelectedNode.FullPath;
foreach (ListViewItem lvi in listView1.SelectedItems)
{
string g = Path.Combine(dir, lvi.Text);
selected.Add(g);
}
AllFiles = selected.ToArray();
Bgw.RunWorkerAsync();
}
}
And in form1:
private void FtpProgress_DoWork(object sender, DoWorkEventArgs e)
{
f = new FtpSettings();
f.Host = "ftP://ftp.newsxpressmedia.com";
f.Username = "...";
f.Password = "...";
files = TV_LV_Basic.ExplorerTree.AllFiles;
StringArrayUploadFiles(sender, e);
}
AllFiles contain the files and paths for example C:\test.txt
Then :
private void StringArrayUploadFiles(object sender, DoWorkEventArgs e)
{
try
{
foreach (string txf in files)
{
string fn = txf;
BackgroundWorker bw = sender as BackgroundWorker;
if (f.TargetFolder != "" && f.TargetFolder != null)
{
createDirectory(f.TargetFolder);
}
else
{
f.TargetFolder = Path.GetDirectoryName(txf);
//createDirectory(f.TargetFolder);
}
string UploadPath = String.Format("{0}/{1}{2}", f.Host, f.TargetFolder == "" ? "" : f.TargetFolder + "/", Path.GetFileName(fn));
Now in txf for example i have C:test.txt
Then in f.TargetFolder i have: C:
Then in UploadPath i have: ftp://ftp.newsxpressmedia.com/C:/eula.1031.txt
But instead C: i need it to look like: ftp://ftp.newsxpressmedia.com/C/eula.1031.txt
And there are sub directories for example then: ftp://ftp.newsxpressmedia.com/C/Sub/Dir/eula.1031.txt
In the menuStrip1_ItemClicked event when i select a file for example test.txt already in this event i did a mess.
FileInfo fi = new FileInfo("temp.txt");
Determine the full path of the file just created.
DirectoryInfo di = fi.Directory;
Figure out what other entries are in that directory.
FileSystemInfo[] fsi = di.GetFileSystemInfos();
to display directoryinfo fullname in console
Console.WriteLine("The directory '{0}' contains the following files and directories:", di.FullName);
Print the names of all the files and subdirectories of that directory.
foreach (FileSystemInfo info in fsi)
Console.WriteLine(info.Name);
Here
My code for opening word file from a directory on local machine on a button click event:
`string path = #"C:\Users\Ansar\Documents\Visual Studio 2010\Projects\GoodLifeTemplate\GoodLifeTemplate\Reports\IT";
List<string> AllFiles = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ParsePath();
}
}
void ParsePath()
{
string[] SubDirs = Directory.GetDirectories(path);
AllFiles.AddRange(SubDirs);
AllFiles.AddRange(Directory.GetFiles(path));
int i = 0;
foreach (string subdir in SubDirs)
{
ListBox1.Items.Add(SubDirs[i].Substring(path.Length + 1, subdir.Length - path.Length - 1).ToString());
i++;
}
DirectoryInfo d = new DirectoryInfo(path);
FileInfo[] Files = d.GetFiles("*.doc")
ListBox1.Items.Clear();
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox1.SelectedItem != null)
{
Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application();
Document document = ap.Documents.Open(path + "\\" + ListBox1.SelectedItem.Text);
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "error", "Please select file;", true);
}
`
This is showing all word files list in the listbox as my requirement is but also the previously opened temporary word files that is (~$nameoffile.docx) I dont want to display this (~$nameoffile.docx) in the list of list box.
The files ~$[something].docx are hidden files. What I would recommend you to do is make sure you filter them out like:
System.IO.DirectoryInfo dirInf = new System.IO.DirectoryInfo(#"C:\myDir\Documents");
var files = dirInf.GetFiles("*.doc").Where(f => (f.Attributes & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden).ToArray();
The search pattern of dirInf.GetFiles works in the same way the windows does.
This is a Lambda Expression:
.Where(f => (f.Attributes & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden)
And this is a bitwise comparison:
(f.Attributes & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden
I am working in C# WinForms. I have made a Windows Explorer that displays the logical directories and then when clicked on them, it shows the files in them in a ListView (old but tricky thing). I get the icons from the system, using:
Icon iconForFile = SystemIcons.WinLogo;
ListViewItem lv = new ListViewItem(filData, imageList1.Images.Count);
lv.Tag = file;
iconForFile = Icon.ExtractAssociatedIcon(file);
string Extension = Path.GetExtension(file);
if (!imageList1.Images.ContainsKey(file))
{
// If not, add the image to the image list.
iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(file);
imageList1.Images.Add(file, iconForFile);
}
lv.ImageKey = file;
listView1.SmallImageList = imageList1;
Now the problem is this: it does show the icons when a directory at first-level is clicked but when I click the folders in any directory (ie. "C"), it doesn't show the icons in the subfolders of a directory. Please help me on how I can customize it. My full code is somewhat like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
PopulateTreeView(treeView1);
}
private void PopulateTreeView(TreeView tv)
{
string[] drives = Environment.GetLogicalDrives();
TreeNode MyCnode = new TreeNode();
MyCnode = new TreeNode("My Computer");
tv.Nodes.Add(MyCnode);
foreach (string drive in drives)
{
TreeNode nodeDrive = new TreeNode();
nodeDrive.Tag = drive;
nodeDrive.Text = drive;
tv.Nodes.Add(nodeDrive);
// tv.Nodes.Add();
// nodeDrive.EnsureVisible();
// treeView1.Refresh();
try
{
//add dirs under drive
if (Directory.Exists(drive))
{
foreach (string dir in Directory.GetDirectories(drive))
{
TreeNode node = new TreeNode();
node.Tag = dir;
node.Text = dir.Substring(dir.LastIndexOf(#"\") + 1);
node.ImageIndex = 1;
nodeDrive.Nodes.Add(node);
}
}
}
catch (Exception)
{
}
MyCnode.Expand();
}
}
public TreeNode GetDirectory(TreeNode parentNode)
{
DirectoryInfo d = new DirectoryInfo(parentNode.FullPath);
DirectoryInfo[] dInfo = d.GetDirectories()
.Where(di => !di.Attributes.HasFlag(FileAttributes.System))
.Where(di => !di.Attributes.HasFlag(FileAttributes.Hidden))
.ToArray();
parentNode.Nodes.Clear();
if (dInfo.Length > 0)
{
TreeNode treeNode = new TreeNode();
foreach (DirectoryInfo driSub in dInfo)
{
treeNode = parentNode.Nodes.Add(driSub.Name);
treeNode.Nodes.Add("");
}
}
return parentNode;
}
private void AddFiles(string strPath)
{
try
{
listView1.BeginUpdate();
listView1.Items.Clear();
//headers listview
// listView1.Columns.Add("File Name", 200);
//listView1.Columns.Add("Size", 80);
//listView1.Columns.Add("Last Accessed", 110);
string[] dirData = new string[3];
string[] filData = new string[3];
string[] files = Directory.GetFiles(strPath);
foreach (string file in files)
{
FileInfo finfo = new FileInfo(file);
FileAttributes fatr = finfo.Attributes;
string name = Path.GetFileNameWithoutExtension(file);
filData[0] = name;
filData[1] = finfo.Length.ToString();
filData[2] = File.GetLastAccessTime(file).ToString();
// Set a default icon for the file.
Icon iconForFile = SystemIcons.WinLogo;
ListViewItem lv = new ListViewItem(filData, imageList1.Images.Count);
lv.Tag = file;
iconForFile = Icon.ExtractAssociatedIcon(file);
string Extension = Path.GetExtension(file);
if (!imageList1.Images.ContainsKey(file))
{
// If not, add the image to the image list.
iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(file);
imageList1.Images.Add(file, iconForFile);
}
lv.ImageKey = file;
listView1.SmallImageList = imageList1;
listView1.Items.Add(lv);
}
}
catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }
listView1.EndUpdate();
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string pathdoubleClicked = listView1.FocusedItem.Tag.ToString();
Process.Start(pathdoubleClicked);
}
private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
{
GetDirectory(e.Node);
treeView1.SelectedNode.Expand();
AddFiles(e.Node.FullPath.ToString());
}
}
for anyone still seeing this as an answer to a search, the assignment of the imagelist needs to be done before the items are added to the imagelist.
private void AddFiles(string strPath)
{
try
{
listView1.BeginUpdate();
listView1.Items.Clear();
listView1.SmallImageList = imageList1;
I have a Repeater that takes all my images in a folder and display it. But what code changes must I make to only allow lets say Image1.jpg and Image2.jpg to be displayed in my repeater. I don"t want the repeater to display ALL the images in my folder.
My Repeater
<asp:Repeater ID="repImages" runat="server" OnItemDataBound="repImages_ItemDataBound">
<HeaderTemplate><p></HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="hlWhat" runat="server" rel="imagebox-bw">
<asp:Image ID="imgTheImage" runat="server" />
</asp:HyperLink>
</ItemTemplate>
<FooterTemplate></p></FooterTemplate>
</asp:Repeater>
My Code behind - PAGE LOAD
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sBasePath = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"];
if ( sBasePath.EndsWith("\\"))
sBasePath = sBasePath.Substring(0,sBasePath.Length-1);
sBasePath = sBasePath + "\\" + "pics";
System.Collections.Generic.List<string> oList = new System.Collections.Generic.List<string>();
foreach (string s in System.IO.Directory.GetFiles(sBasePath, "*.*"))
{
//We could do some filtering for example only adding .jpg or something
oList.Add( System.IO.Path.GetFileName( s ));
}
repImages.DataSource = oList;
repImages.DataBind();
}
}
My Code behind - Repeater's ItemDataBound event code
protected void repImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
string sFile = e.Item.DataItem as string;
//Create the thumblink
HyperLink hlWhat = e.Item.FindControl("hlWhat") as HyperLink;
hlWhat.NavigateUrl = ResolveUrl("~/pics/" + sFile );
hlWhat.ToolTip = System.IO.Path.GetFileNameWithoutExtension(sFile);
hlWhat.Attributes["rel"] = "imagebox-bw";
Image oImg = e.Item.FindControl("imgTheImage") as Image;
oImg.ImageUrl = ResolveUrl("~/createthumb.ashx?gu=/pics/" + sFile + "&xmax=100&ymax=100" );
}
}
ANSWER:
My updated Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sBasePath = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"];
if ( sBasePath.EndsWith("\\"))
sBasePath = sBasePath.Substring(0,sBasePath.Length-1);
sBasePath = sBasePath + "\\" + "pics";
System.Collections.Generic.List<string> oList = new System.Collections.Generic.List<string>();
string[] extensions = { "*.jpg", "*.png" };
List<string> files = new List<string>();
foreach (string filter in extensions)
{
files.AddRange(System.IO.Directory.GetFiles(sBasePath, filter));
oList.Add(System.IO.Path.GetFileName(filter));
}
repImages.DataSource = oList;
repImages.DataBind();
}
What format are the image names that you want to display? If you know that you can construct a filter to use when listing the contents of the directory:
string[] files = Directory.GetFiles(folder, "*1.jpg");
Will list all the jpg files that end in "1"
EDIT:
Instead of having:
foreach (string s in System.IO.Directory.GetFiles(sBasePath, "*.*"))
{
//We could do some filtering for example only adding .jpg or something
oList.Add( System.IO.Path.GetFileName( s ));
}
You'd have:
string[] files = System.IO.Directory.GetFiles(sBasePath, "*.jpg")
foreach (string s in files)
{
oList.Add( System.IO.Path.GetFileName( s ));
}
EDIT 2:
I've done a quick search and it looks like Get Files won't take multiple extensions, so you'll have to search for each type of extension separately:
string[] extensions = {"*.jpg" , "*.png" };
List<string> files = new List<string>();
foreach(string filter in extensions)
{
files.AddRange(System.IO.Directory.GetFiles(path, filter));
}
foreach (string s in files)
{
oList.Add( System.IO.Path.GetFileName( s ));
}
Easiest way to is load them all into a List<> and then use Linq to filter out the ones you want.
VS2005
public class GetFiles
{
public static void Main(string[] args)
{
FileInfo[] files =
new DirectoryInfo(#"D:\downloads\_Installs").GetFiles();
ArrayList exefiles = new ArrayList();
foreach (FileInfo f in files)
{
if (f.Extension == ".exe") // or whatever matching you want to do.
{
exefiles.Add(f);
}
}
foreach (FileInfo f in exefiles)
{
Console.WriteLine(f.FullName);
}
Console.ReadKey();
}
}
VS2008
public class GetFiles
{
public static void Main(string[] args)
{
FileInfo[] files =
new DirectoryInfo(#"D:\downloads\_Installs").GetFiles();
var exefiles = from FileInfo f in files
where f.Extension == ".exe"
select f;
foreach (FileInfo f in exefiles)
{
Console.WriteLine(f.FullName);
}
Console.ReadKey();
}
}
What you will need to do is filter out all the images you do not wish to display from your list before you bind it to your repeater control.