How to use a hyperlink in wpf to get a file on a network drive?

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

.. Therefore, I do not use any impersonation.

Do we have something similar in WPF?

EDIT : I want to open an excel file in a network location ... when the user clicks a link or button. Also, I don’t want to use any kind of impersonation ... because we don’t need to impersonate a-href.

+3
source share
3 answers
<Hyperlink NavigateUri="file:///networkShare/file">
    Excel File
</Hyperlink>
+2
source

Just include it Hyperlinkinside TextBlockand use ValueConverterto reference 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();
        }
    }
}

, , 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>

0

Use this solution: How to make a simple hyperlink in XAML? so that the button looks like a hyperlink. (Hyperlinks do not work everywhere.) When you click a button, do the following:

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

Source: https://habr.com/ru/post/1796730/


All Articles