Пример #1
0
        public void OpenDialog(OpenFileMessage msg)
        {
            var ofd = new OpenFileDialog();

            ofd.RestoreDirectory = true;
            var result = ofd.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (msg.OpenStream)
                {
                    using (var stream = ofd.OpenFile())
                    {
                        msg.OpenStreamAction(stream);
                    }
                }
                else
                {
                    msg.PassFileNameAction(ofd.FileName);
                }
            }
        }
Пример #2
0
        public async void OpenDialog(OpenFileMessage msg)
        {
            var ofd = new OpenFileDialog();

            ofd.AllowMultiple = false;
            var result = await ofd.ShowAsync();

            if (result != null && result.Length == 1)
            {
                if (msg.OpenStream)
                {
                    using (var stream = new FileStream(result.First(), FileMode.Open))
                    {
                        msg.OpenStreamAction(stream);
                    }
                }
                else
                {
                    msg.PassFileNameAction(result.First());
                }
            }
        }