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;
                }
               
            }
        }

 

前台代码

<Page x:Class="MyAppWpfApplication.MyAppDefinePage"
      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">

    <Grid Width="742" Height="358">
        <Grid.RowDefinitions>
            <RowDefinition Height="150*" />
            <RowDefinition Height="208*" />
        </Grid.RowDefinitions>

        <GroupBox Header="应用" HorizontalAlignment="Left" Margin="12,4,0,0" Name="groupBox1" Width="532">
            <Grid Height="122" Width="505">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0*" />
                    <ColumnDefinition Width="505*" />
                </Grid.ColumnDefinitions>
                <Button Content="..." Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="392,47,0,0" Name="button1" VerticalAlignment="Top" Width="24" Click="button1_Click" />
                <Label Content="path:" Grid.Column="1" Height="28" HorizontalAlignment="Left" Margin="15,46,0,0" Name="lblPath" VerticalAlignment="Top" />
                <TextBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="60,48,0,0" Name="tbPath" VerticalAlignment="Top" Width="330"/>
               
            </Grid>
        </GroupBox>
    </Grid>
</Page>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值