Beispiel #1
0
        /// <summary>
        /// 链接点击事件-查看文件
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">事件参数</param>
        private void link_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Attachment attach = (sender as Label).DataContext as Attachment;

            ConfigUtil config    = new ConfigUtil("FILEPATH");
            string     directory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.Get("FILEPATH"));

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            string filepath = System.IO.Path.Combine(directory, attach.Path);

            if (!File.Exists(filepath))
            {
                MoldPartInfoServiceClient client = new MoldPartInfoServiceClient();
                byte[] data = client.GetFileByName(attach.Path);
                if (data == null)
                {
                    MessageBox.Show("文件不存在");
                    return;
                }
                FileUtil.SavaFIle(filepath, data);
            }
            if (File.Exists(filepath))
            {
                Process.Start(filepath);
            }
        }
        /// <summary>
        /// 链接点击事件-查看文件
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">事件参数</param>
        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            Attachment attach = (sender as Hyperlink).DataContext as Attachment;

            ConfigUtil config = new ConfigUtil("FILEPATH");
            string directory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.Get("FILEPATH"));
            if (!Directory.Exists(directory))
                Directory.CreateDirectory(directory);
            string filepath = System.IO.Path.Combine(directory, attach.Path);
            if (!File.Exists(filepath))
            {
                MoldPartInfoServiceClient client = new MoldPartInfoServiceClient();
                byte[] data = client.GetFileByName(attach.Path);
                if (data == null)
                {
                    MessageBox.Show("文件不存在");
                    return;
                }
                FileUtil.SavaFIle(filepath, data);
                //if (FileUtil.SavaFIle(filepath, data))
                //    MessageBox.Show("文件保存成功,目录为:" + filepath);
                //else
                //    MessageBox.Show("文件保存失败");
            }
            if (File.Exists(filepath))
                Process.Start(filepath);
        }