Chandan Pasunoori
Chandan Pasunoori

Reputation: 959

openfiledialog error for selecting used files

try
        {
            OpenFileDialog dialog = new OpenFileDialog();
            String appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string tempPath = System.IO.Path.GetTempPath();
            dialog.InitialDirectory = tempPath;
            dialog.Multiselect = true;
            dialog.Filter = "Temp files (*.tmp)|*.tmp";
            dialog.ValidateNames = false;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string[] filePaths = dialog.SafeFileNames;
                foreach (string s in filePaths)
                    richTextBox1.Text += s;
                //MessageBox.Show("");
            }
        }
        catch 
        {
            MessageBox.Show("Error Occured");
        }

when i selecting files (which already in use in another application) in openfiledialog I getting error but still I want their paths...

enter image description here

Upvotes: 0

Views: 809

Answers (3)

DEXTER360
DEXTER360

Reputation: 183

Setting openFileDialog.ValidateNames = false; worked for me.

Upvotes: 1

Isaac Broyles
Isaac Broyles

Reputation: 111

This is apparantly an issue with OpenFileDialog and MultiSelect "true." See this post for a discussion on the problem (and some possible solutions):

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/56fbbf9b-31d5-4e89-be85-83d9cb1d538c/

Upvotes: 2

SirRoot
SirRoot

Reputation: 259

try

String tempPath = System.IO.Path.GetDirectoryName(dialog.FileName) + @"\";

Upvotes: 0

Related Questions