Hello.I receive the following error Error: "The path is not of a legal form" in C# in the code
string location = "List.txt";
// Read lines
StreamReader reader = new StreamReader(location); string[] file_lines = (reader.ReadToEnd()).Split('\n'); // Add in Lista foreach (string one_line in file_lines){
string file_location = one_line.TrimEnd();System.IO.
FileInfo info_item = new FileInfo(file_location); if (info_item.Extension == ".mp3"){
ListViewItem List_Item = new ListViewItem(info_item.Name, 0);List_Item.SubItems.Add(
"XX:XX");List_Item.SubItems.Add(
"Necunoscut");List_Item.SubItems.Add(locatie_fisier_lista);
Box_Lista_Melodii.Items.AddRange(
new ListViewItem[] { List_Item });}
}

Error: "The path is not of a legal form" in C#
Prabu.
NozFx
Nille
N. Farr
- I have a LISTVIEW with 3 columns (Name, Duration, Path).Is like a playlist.When the user double-click a item, will be played the information from Path (C:\Music.mp3). THIS IS WORKING VERY GOOD
- When the application is closing, it saves the Path in a textfile, line per line , like this:
using (StreamWriter sw = new StreamWriter("List.txt"))
{
foreach (ListViewItem item_for_saving in Box_Lista_Melodii.Items)
{
if (item_for_saving.SubItems.Count >= 4)
{
string item_name = item_for_saving.SubItems[2].Text;
sw.WriteLine(item_name);
}
else
{
}
}
OK THIS IS WORKING VERY GOOD.IT SAVES SOMETHING LIKE THIS:
C:/Music.mp3
When the application is starting it must add the item from LIST.TXT in LISTVIEW
- it gets a line (that will be the PATH) and then with System.IO.File(PATH) must get information about file (Name, and Duration) >> this is NOT WORKING
WHY
collide
That would result in this problem.
Softwaremaker
Jon Braganza
yanivpinhas
Hi
As suggested, can you please write here what each line is currently reading in the foreach loop and also a sample from the list.txt
As well as this, by looking at your example - you have said that "it saves something like this : C:/music.mp3"
that will of course through an exception as the path is an illegal path for the class to work with. it should be a backslash '\' rather than a forward '/'
Make sure that initially when you are reading the file paths to the listbox that it displays the full path to the file in a correct format, ie:
c:\folder\mymusic.mp3
satya999
I try to verify the application
1 - When I close the program all the things seem to be OK in LIST.TXT
2 - I replace SystemInfo(line) with MessageBox.Show(line) to see what is containing that line, and all seem to be OK.
3 - I tried with Trim(),TrimEnd(),TrimStart() and is not working.Error: " The path is not of a legal form"
rick_james
well the path/file you have given an example of seems to be ok.
As you have said, when the application is closed the application writes the files back to the text file - correct
The first 2 lines which you have posted - are these of the file itself or what is going through the foreach loop
If you can, please report back on this:
run the application
save the listbox items (Containing the path and filename)
open the textfile, does the path look correct (post a single line)
run the application again, make it read the textfile - does it read it (assuming the path looks correct)
at what part/how far in the foreach loop does it throw the exception what was the value of the variable in the foreach loop that caused the exception to be thrown
it could also be that there maybe an entry somewhere which is an invalid entry causing it to throw the exception.
SalmonCreekGames
F:\My Music\Music 2006\Andreea Banica - Indragostiti - www.HOmp3.Tk -.mp3
F:\My Music\Music 2006\HI-Q Razna!.mp3
The problem is that the program itself saves the path when the user close the application, but when the application is starting he is not recognize the line.
JamesE
To me it looks like the current line has some invalid path characters or something as such.
Are you able to get a list of each file it is reading and display it here for our and your benefit This is so we can see what line the error is happening on and to see what entries are in the text file/lines array
Ning
in your foreach loop check the length of the line first before proceeding to do the code:
foreach (string curLine in theLinesInFile)
{
if (curLine.Length > 0)
{
//do stuff
}
}
Jough