Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.CheckFileExists = true;
            openFileDialog.AddExtension = true;
            openFileDialog.Multiselect = true;
            openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
            DialogResult result = openFileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string[] files = openFileDialog.FileNames;
            }


in this i want to convert string array to fileinfo array.fileinfo array is useful for simple access pdffile properties like filename,file path,extension,size,content of file.

my string array like
C#
string[] files = openFileDialog.FileNames;




pls help me.
Posted
Comments
Sinisa Hajnal 9-Feb-15 7:37am    
There is a class FileInfo (https://msdn.microsoft.com/en-us/library/system.io.fileinfo%28v=vs.110%29.aspx) - is this the array you mention or you just want some collection of the information about the files?
Nathan Minier 9-Feb-15 7:40am    
Assuming that you're using Windows Forms due to the use of the OpenFileDialog class, you can just use OpenFileDialog.Files to get the FileInfo structs of the various selected items.

1 solution

Try this;

var fileInfos = openFileDialog.FileNames.Select(x => new FileInfo(x)).ToArray();


Remember to import System.Linq.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900