Frage

hi,

i am able to get all files in a directory with their path and their files with this code.

    List<ListItem> files = new List<ListItem>();
                   
    string Myfile = "";
               
    foreach (string filePath in filePaths)
    {
    files.Add(new ListItem(Path.GetFileName(filePath), filePath));
    }

But i cant get sizes of these files. How can i do that. i cant use size property like,

     files[0].size;
War es hilfreich?

Lösung

You could create a FileInfo instance and then ask for the size using the Length property:

foreach (string filePath in filePaths)
{
    FileInfo fi = new FileInfo(filePath);
    long fileSizeInBytes = fi.Length;
    files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}

The Length property will give you the file size in bytes that you could use.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top