Before we look at that, and try to sort it out, what are you trying to do? You do realize that your ReadDoc method will return the data for the last file it finds in the folder you specify? So if there are six files, it will read them all, and return the final one - whichever that happens to be in the system your app is running in? And that there is a very good chance that it will fail for access denied reasons on a huge number of folders?
And that if you pass a filename as your code implies, it will fail anyway? And if it's a path, then your extension info will be wrong?
And that it could be replaced by File.ReadAllBytes if you specify the file you want to read rather than a path?
See OP comments below with code
Ok, so the ListView has individual file names in it?
So each ListViewItem is a single file, complete with it's path.
To read the file content:
foreach (ListViewItem item in listOfLoadedFiles.Items)
{
string path = item.Text;
if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
{
byte[] data = File.ReadAllBytes(path);
long length = new FileInfo(path).Length;
string extension = Path.GetExtension(path);
... continue and write the file to SQL.
}
}
And dump the ReadDoc method completely!