如何使用wpf中的超链接获取网络驱动器中的文件?

发布于 2024-10-20 17:59:38 字数 195 浏览 1 评论 0原文

我有一个网络应用程序...我可以从网络驱动器获取 Excel 文件...使用

..所以我没有使用任何模拟。

我们有类似 WPF 的东西吗?

编辑: 我想在网络位置打开 Excel 文件...当用户单击链接或按钮时。另外,我不想使用任何模拟...因为我们不必在 a-href 的情况下进行模拟。

I have a web application...where I can get an excel file from network drive...using

..So I am not using any impersonation.

Do we have something similar to that in WPF ?

EDIT:
I want to open excel file in network location...when user click a link or button. Also, i dont want to use any impersonation...as we dont have to impersonate in case of a-href.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

节枝 2024-10-27 17:59:39

只需将 Hyperlink 包含在 TextBlock 中,并使用 ValueConverter 来引用网络值。

里面:View.xaml

            <TextBlock x:Name="FileNamePresenter" Grid.Row="1" Text="{Binding FileName}" Margin="0,0,0.001,0" HorizontalAlignment="Stretch" d:LayoutOverrides="Height" Width="Auto" Grid.Column="1" >
            <Hyperlink x:Name="FileLink" NavigateUri="{Binding FileName,  ConverterParameter=FileName, Converter={StaticResource FileConverter}}"/>
            </TextBlock>

valueConverter

namespace some.Helpers
{
    public  class JobFileConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string FileLocationPath = "";
            try
            {
                if (value != null)
                {
                    FileLocationPath= string.Format(@"file://SomesServer/f$/SomeFile/{0}.pdf",value);


                }

            }
            catch { }
            return FileLocationPath;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

,最后是App.xaml(或资源字典)里面的胶水......

<Application x:Class="some.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:some.ViewModel"
             xmlns:helper="clr-namespace:some.Helpers"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             StartupUri="JobList.xaml"
             mc:Ignorable="d">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="someApp.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!--Global View Model Locator-->
            <vm:ViewModelLocator x:Key="Locator"
                d:IsDataSource="True" />
            <helper:JobStatusImageConverter  x:Key="JobStatusConverter"/>
            <helper:JobBindingImageConverter x:Key="JobBindingConverter"/>
            <helper:JobFileConverter x:Key="FileConverter"/>
            <Style x:Key="HeadingStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="TextWrapping" Value="NoWrap"/>
                <Setter Property="TextTrimming" Value="None"/>
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="#FFA52323" Direction="339" ShadowDepth="0"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </Application.Resources>

Just include the Hyperlink inside a TextBlock and use a ValueConverter to Reference To the network Value.

inside: View.xaml

            <TextBlock x:Name="FileNamePresenter" Grid.Row="1" Text="{Binding FileName}" Margin="0,0,0.001,0" HorizontalAlignment="Stretch" d:LayoutOverrides="Height" Width="Auto" Grid.Column="1" >
            <Hyperlink x:Name="FileLink" NavigateUri="{Binding FileName,  ConverterParameter=FileName, Converter={StaticResource FileConverter}}"/>
            </TextBlock>

valueConverter

namespace some.Helpers
{
    public  class JobFileConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string FileLocationPath = "";
            try
            {
                if (value != null)
                {
                    FileLocationPath= string.Format(@"file://SomesServer/f$/SomeFile/{0}.pdf",value);


                }

            }
            catch { }
            return FileLocationPath;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

and lastly inside App.xaml ( or resource dictionary) the glue as it were...

<Application x:Class="some.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:some.ViewModel"
             xmlns:helper="clr-namespace:some.Helpers"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             StartupUri="JobList.xaml"
             mc:Ignorable="d">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="someApp.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!--Global View Model Locator-->
            <vm:ViewModelLocator x:Key="Locator"
                d:IsDataSource="True" />
            <helper:JobStatusImageConverter  x:Key="JobStatusConverter"/>
            <helper:JobBindingImageConverter x:Key="JobBindingConverter"/>
            <helper:JobFileConverter x:Key="FileConverter"/>
            <Style x:Key="HeadingStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="TextWrapping" Value="NoWrap"/>
                <Setter Property="TextTrimming" Value="None"/>
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="#FFA52323" Direction="339" ShadowDepth="0"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </Application.Resources>

み零 2024-10-27 17:59:38
<Hyperlink NavigateUri="file:///networkShare/file">
    Excel File
</Hyperlink>
<Hyperlink NavigateUri="file:///networkShare/file">
    Excel File
</Hyperlink>
ぃ双果 2024-10-27 17:59:38

使用此解决方案:如何在 XAML 中创建简单的超链接?
使按钮看起来像超链接。 (超链接并非在所有地方都有效。)
单击按钮时,执行如下操作:

Process explorer = new Process();  
explorer.StartInfo.FileName="explorer.exe";  
explorer.StartInfo.Arguments = "/n, /e, /select," + path;  
explorer.Start();

Use this solution: How to make a simple hyperlink in XAML?
to make a button look like a hyperlink. (Hyperlinks don't work everywhere.)
When clicking the button, do something like this:

Process explorer = new Process();  
explorer.StartInfo.FileName="explorer.exe";  
explorer.StartInfo.Arguments = "/n, /e, /select," + path;  
explorer.Start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文