I have a web application.开发者_C百科..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.
<Hyperlink NavigateUri="file:///networkShare/file">
Excel File
</Hyperlink>
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();
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>
精彩评论