Populating a ListBox with list of files in a folder
-
Hi. I am wondering how I can get a list of files in a folder on the server to appear on a webpage. I don´t know how to get the contents of a folder into a ListBox. Is there perhaps some other webcontrol that is better suited for this? This code I put in the Page_Load event: DirectoryInfo di = new DirectoryInfo(@"c:\somefoldername"); FileInfo [] fi = di.GetFiles(); foreach (FileInfo fiTemp in fi) ListBox1 By looking at the code you can see where I am stuck. Can someone please help me? Best regards, F
-
Hi. I am wondering how I can get a list of files in a folder on the server to appear on a webpage. I don´t know how to get the contents of a folder into a ListBox. Is there perhaps some other webcontrol that is better suited for this? This code I put in the Page_Load event: DirectoryInfo di = new DirectoryInfo(@"c:\somefoldername"); FileInfo [] fi = di.GetFiles(); foreach (FileInfo fiTemp in fi) ListBox1 By looking at the code you can see where I am stuck. Can someone please help me? Best regards, F
Hi there. Here is an example of populating a ListBox with file names[^].
-
Hi there. Here is an example of populating a ListBox with file names[^].
Thanks for your help. I pasted the code you pointed out into my code in VS 2005 and I got a bunch of errors that don´t seem to make sense. Is there a difference between VS 2003 and VS 2005 how this is done. Here is what I did and get loads of errors: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { public string FileName; //set directory and array Directory myDirectory; ArrayList values = new ArrayList(); //get files String [] files = Directory.GetFiles(@"N:\Myndir","*"); //iterate through list, replace path info, and add to the listbox //with the Add method. for(int i=0;i
-
Thanks for your help. I pasted the code you pointed out into my code in VS 2005 and I got a bunch of errors that don´t seem to make sense. Is there a difference between VS 2003 and VS 2005 how this is done. Here is what I did and get loads of errors: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { public string FileName; //set directory and array Directory myDirectory; ArrayList values = new ArrayList(); //get files String [] files = Directory.GetFiles(@"N:\Myndir","*"); //iterate through list, replace path info, and add to the listbox //with the Add method. for(int i=0;i
What errors did you get?
-
What errors did you get?
Hi. I got a bunch of strange errors but I think there must have been something wrong with the VS 2005 I am using because everything works very well in my VS 2003. It´s strange. Thanks very much for your help! By the way, you wouldn´t happen to know of some simple way of making an app stop working after a period of time. I finished making an app and I want it to only work until some day. It´s doesn´t have to be a bulletproof way as long as it is simple and works most of the time. I was thinking of perhaps making a thread that checks to see, for instance, if the year is 2007 and then it will disable some part (like the menus) of the app. How is this done if it is possible to do it this way. Thank you, F