开发者

openfiledialog error for selecting used files

开发者 https://www.devze.com 2023-04-13 07:26 出处:网络
try { OpenFileDialog dialog = new OpenFileDialog(); String appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
try
        {
            OpenFileDialog dialog = new OpenFileDialog();
            String appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        开发者_StackOverflow中文版    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...

openfiledialog error for selecting used files


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/


Setting openFileDialog.ValidateNames = false; worked for me.


try

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号