WPF 调用OpenFileDialog对象,实现获取文件上传路劲

wpf  好像 没有直接的文件上传控件,反正我没找到

我在网上找了好久,没有简单直接的例子,只好自己放了一个按钮,然后调用OpenFileDialog对象,实现获取文件上传路劲

 

后台代码

 private void button1_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofld = new System.Windows.Forms.OpenFileDialog();
            if (ofld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string text = ofld.FileName;
                //string s = System.IO.Path.GetFileNameWithoutExtension(ofld.FileName).ToString();
                if (text != "" || text != null)
                {
                    this.tbPath.Text = text;
                }
               
            }
        }

 

前台代码

      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:loc="clr-namespace:mgen_fileSelector1"
      mc:Ignorable="d"
      d:DesignHeight="360" d:DesignWidth="738"
 Title="MyAppDefinePage" xmlns:my="clr-namespace:MyAppWpfApplication.UC">

   
       
           
           
       

       
           
               
                   
                   
               

               

你可能感兴趣的:(WPF 调用OpenFileDialog对象,实现获取文件上传路劲)