I have mafe a simple object using fileInfo class as:
DirectoryInfo myDirectory = new DirectoryInfo(@"d:\Books");
FileInfo[] files = myDirectory.GetFiles();
foreach (FileInfo file in files)
{
try
{
file.OpenRead();
break;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
The first file in the directory(Books) is PDF. The code throw no exception. Still the particular file doesn’t open. what code i am missing or i am doing any error. Thanks for any assistence.
You should use
Process.Startto open files in default application, if you openpdffile, it will open in Adobe Reader if Adobe Reader is default application forpdf:FileInfo.OpenReadreturns a read-onlyFileStreamobject, not for opening file.