i have direcory with variable amount of files.
When starting a C#-windows-form i want to read out all the filenames of a directory and show them in a dropdown-combobox. The selected filename should then be returned when pressing a button.
How can i do this?
Thank you for the help
Solved:
System.IO.DirectoryInfo myPath = new System.IO.DirectoryInfo(myPathIni);
foreach (System.IO.FileInfo f in myPath.GetFiles())
{
comboBox1.Items.Add(f.Name);
}
Related
I'm interested in seeing if I can modify some XMP within an image file. I'm using the following code:
var items = MetadataExtractor.ImageMetadataReader.ReadMetadata(_filename);
foreach (var item in items)
{
if(item.Name == "XMP")
{
var y = new XmpCore.Impl.XmpMeta();
var xmp = item as MetadataExtractor.Formats.Xmp.XmpDirectory;
foreach(var xd in xmp.XmpMeta.Properties)
{
if(xd.Path == "drone-dji:AbsoluteAltitude")
{
var alt = Convert.ToDecimal(xd.Value.Substring(1,xd.Value.Length-1));
alt -= 100;
xmp.XmpMeta.SetProperty(xd.Namespace, xd.Path, alt.ToString());
}
}
xmp.SetXmpMeta(xmp.XmpMeta);
}
}
I know I'm missing something breathtakingly obvious but I don't know this library well enough to figure it out.
No exceptions come up but when I open up the file the XMP field is still the same. When I iterate thru the xmp properties after I set the property it does reflect correctly but when I end the program the file stays the same. I'm sure there's something to do with writing back to the image path but I have no idea where in this library I do that. Any help would be greatly appreciated.
MetadataExtractor doesn't support modifying files. You can update the data structure, as you show, but there's no way to write those changes back to your original file.
I searched for two hours, here on Stackoverflow and on other forums. But i can't find a solution for my problem. I have to be able to change the properties of an object that has a name that I don't know. Now i try to explain better:
The user drag some files in a form, and i get in a array() all the paths of the dragged files. For each path in files() i add to a panel a usercontrol that is the interface of an uploader. (My application it's kind of an uploader). Good, imagine that the user dragged 4 files, i have 4 different usercontrols, named "Uploader1", "Uploader2", "Uploader3" and "Uploader4". I need to change the text of a label in the uploader1, but i can't write:
Uploader1.LabelExample.Text = "Example"
Becouse it doesn't exist! (Not yet!)
So i tryed this method.
Dim UploadCounter as Integer = 1
Dim CurrentUploader = CType(Panel.Controls("Uploader" & UploaderCounter.ToString), UploadBanner)
CurrentUploader.LabelExample.Text = "Example"
I write the same with DirectCast and TryCast, but nothing.
I try also:
For Each Uploader With{.Name = "Uploader1"} as UploaderControl in Panel.Controls
Uploader.LabelExample.Text = "Example"
Next
I searched everywhere for "convert string to an object in vb.net" but i can't find anything that work! They all return "System.NullReferenceException: 'Object reference not set to an instance of an object.'"
Sorry for my bad bad english, thanks for all that will help me! need really!
Good day all, I have read through all the posts I could find, but none helped me.
I have a listbox that should list all the files in a folder called data that is in the same location as my app.
Problem is, I tried varies codes but i'm still failing to get the folder to show in my listbox.
The filepath is variable as the exe file is in diff locations on diff pc's.
Here is my code:
string Cust = System.AppDomain.CurrentDomain.BaseDirectory + #"data\";
string[] txtfiles = Directory.GetFiles(Cust, "*.txt");
foreach (string file in txtfiles)
custList.Items.Add(file);
When I finally get the files to list, I will need to be able to click on one and have its values display in labels on my form.
Any help would be great.
Thanx
Your code should work, your problem is most likely how you are concatenating your path:
Change:
string Cust = System.AppDomain.CurrentDomain.BaseDirectory + #"data\";
To:
string Cust = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "data");
How to list all files in folder by start name but without loop?
Example: in my folder there are files:
filename1.jpg<br/>
filename2.jpg<br/>
filename3.jpg<br/>
kienvt01.jpg<br/>
kienvt02.jpg<br/>
kienvt03.jpg<br/>
....<br/>
...<br/>
i want to list all file with file name start with "kienvt", but not using loop.
i'd try with Directory.GetFiles but not ok.
Please help me.
Thank you!
Dim output As String
output = String.Join("<br />", System.IO.Directory.GetFiles(path, "kienvt*"))
The value of output should be:
"kienvt01.jpg<br />kienvt02.jpg<br />kienvt03.jpg<br />"
I want to get a number of songs from a folder and list their names in a WPF Listview.
I also want each item in the list view to be a draggable file and can be copied from the list to the desktop. I've achieved this on one button, using the code:
Point mpos = e.GetPosition(null);
Vector diff = this.start - mpos;
string[] files = new String[1];
files[0] = #"C:\Song1.mp3";
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, files),
DragDropEffects.Copy);
For that each item in the list needs to have a filepath string associated with it.
How do I:
1. Get the files from a folder and list them.
2. Associate with each one a filepath string for the dragging.
Thanks!
You can use Directory.GetFiles() to get all the file paths in a folder and then use Path.GetFileName() (or Path.GetFileNameWithoutExtension()) on each path returned to get just the file names.