Populating listbox with files to include creation date - c#

I am attempting to populate a listbox with the contents of a directory. I have it populating but I need the creation date/time included in the list.
This is what I have so far:
var filter = Path.GetFileName(GlobalVariables.EbillFile);
listBox_Restore.DataSource = Directory.GetFiles(GlobalVariables.EbillBackupDirectory, $"{filter}.*", SearchOption.TopDirectoryOnly);
It gives me this:
ListBox Contents
How do I go about adding the date to this list? Should I be using a different control?

You should use DirectoryInfo.GetFiles() to get more information about each file - for instance created date, last used date, size etc.
And then use a ListView to show the result.

Related

How to select an item in excel's dropdown list using C#?

I'm trying to make a desktop application (WinForms) that reads an Excel template file and manipulates with it. So far i have managed to write data to specific column and save changes to the file from the application, but i have a problem.
My Excel template file has a drop-down populated with items from another sheet in one column.
Here is how my template looks like: My Excel template file
Sheet2 that populates the dropdown in Sheet1: Sheet2 - used to populate dropdown in Sheet1
I would like to be able to read those items in my application and select one of them,and also save changes to the file (with the selected item in the dropdown).
If that's not possible, i would like to know if there's any possibility to select an item in a specific index from the application (for example second or third item in the dropdown list and save changes to the file)
I have searched a lot to resolve this issue, but i haven't got any correct answer yet.

How to Add/Remove items to ComboBox Collection?

I'm trying to remove selected item from ComboBox Collection:
Items are added manually, as a Collection, in design time.
buttonClick:
cb01.Items.Remove(cb01.SelectedItem);.
This deletes the item, but next time I open the Form - the item appears again.
Must I have a database for 5-6 items ?
Please help.
This cb01.Items.Remove(cb01.SelectedItem); will only remove from the combobox, not from the datasource binded to the combobox. You may remove it from the datasource and re bind the source.
If you are binding the combobox with an array in your code, then you may save the array on a persistent storage, either a database table, or XML file and upon deletion from combobox you should remove the element from the array and save the changes to the persistent storage
You can also work with Files (existing in System.IO Namespace) if you don't want to use a database server. for 5/6 items it's not worth to use database, and in a file you can easily find the item's line and delete the line.
hope it helps.

Get a Sharepoint ListItem Based on Date?

I have a Sharepoint List which is sorted by a Report Date.
Within a Visual Webpart I have created an html report which references the ListItems. One of the options on this Webpart is to change the date. If the user changes the date I need to be able to retrieve the ListItem corresponding to that Date from the List. Using c#, how can I get a handle on the Item in this way?
Thanks
I think you have your answer here
http://snahta.blogspot.com/2009/04/getting-list-item-updated-in-past-few.html
Few more good tips # http://snahta.blogspot.com/2009/07/spquery-few-important-things.html

Set selected value in a SharePoint Dropdown list

We are using SharePoint 2010 Foundation.
We have an item in a list that is a dropdown with values from another list.
When we access the list as a SharePoint list it works fine, we can select a value, save the list, the next time we access the list the correct value is selected.
We have programmed a form that will updated the list. When we pull up the form, select a value and save it, we can see by accessing the list directly that the value has been saved.
However, when we pull up the form again it is the first item in the list that is selected. Have tried storing the selected value is a temp variable before binding the list but have not been able to get it to work. Anyone know how to fix this?
We found a solution.
The trick was to get the number that is the first part of the ToString of the SPListItem, before binding the list.
Then use that number to set the selected value after the list is bound
Parameters:
SPListItem currentItem, string fieldName
Code:
string selectedValue = currentItem[fieldName].ToString().Substring(0,1);
//... Bind list
ddlLookup.SelectedValue = selectedValue;

Dynamically populate an InfoPath DropownList with managed code

I have an InfoPath form with custom C# code, and a Sharepoint list. I have a dropdownlist in the InfoPath form that I want to populate with a certain field from the Sharepoint list (I want the InfoPath dropdownlist to contain this field's value from every item in the Sharepoint list. I can successfully get the list of values I need from Sharepoint in my managed code, but I do not see how I can get these values into the dropdownlist (either bind to the list, or add each item in the list one by one). I thought I could modify the XML of the dropdownlist to insert my items, but the XML only contains the first item in the dropdownlist:
<my:RelatedRiskID xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-20T18:12:59">Option 1</my:RelatedRiskID>
I feel like this should be possible, but I can't find any resources on how to do it. Thanks in advance for the help.
If you plan to populate your dropdown list with a SharePoint list then you need to
create a data connection to the said SharePoint list
in the dropdown list Data tab, get the data externally and select the said data connection

Categories

Resources