稳扎稳打Silverlight(67) - 5.0被信任的应用程序之访问本地文件系统, 支持多窗口, 被信任的程序在浏览器中运行, Call Windows API
2012-03-22 08:31
911 查看
[索引页]
[源码下载]
[align=center]稳扎稳打Silverlight(67) - 5.0被信任的应用程序之访问本地文件系统, 支持多窗口, 被信任的程序在浏览器中运行, Call Windows API[/align]
作者:webabcd
介绍
Silverlight 5.0 被信任的应用程
AccessFileSystem - 访问本地文件系统
MultipleWindows - 支持多窗口
In Browser - 被信任的程序在浏览器中运行
Call Windows API
在线DEMO
/article/4589702.html
示例
1、AccessFileSystem(访问本地文件系统)
TrustedApplication/AccessFileSystem.xaml
TrustedApplication/AccessFileSystem.xaml.cs
2、MultipleWindows(支持多窗口)
TrustedApplication/MultipleWindows.xaml
TrustedApplication/MultipleWindows.xaml.cs
3、In Browser(被信任的程序在浏览器中运行)
TrustedApplication/InBrowser.xaml
4、Call Windows API
TrustedApplication/CallWindowsAPI.xaml
TrustedApplication/CallWindowsAPI.xaml.cs
OK
[源码下载]
[源码下载]
[align=center]稳扎稳打Silverlight(67) - 5.0被信任的应用程序之访问本地文件系统, 支持多窗口, 被信任的程序在浏览器中运行, Call Windows API[/align]
作者:webabcd
介绍
Silverlight 5.0 被信任的应用程
AccessFileSystem - 访问本地文件系统
MultipleWindows - 支持多窗口
In Browser - 被信任的程序在浏览器中运行
Call Windows API
在线DEMO
/article/4589702.html
示例
1、AccessFileSystem(访问本地文件系统)
TrustedApplication/AccessFileSystem.xaml
<navigation:Page x:Class="Silverlight50.TrustedApplication.AccessFileSystem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" d:DesignWidth="640" d:DesignHeight="480" Title="AccessFileSystem Page"> <StackPanel x:Name="LayoutRoot" HorizontalAlignment="Left"> <TextBlock Text="在不使用 OpenFileDialog 和 SaveFileDialog 的情况下,访问本地文件系统" /> <!-- 显示“C盘”中的文件夹列表 --> <ListBox Name="listBoxDirectory" HorizontalAlignment="Left"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" Margin="1" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <!-- 显示“C盘”中的文件列表 --> <ListBox Name="listBoxFile" HorizontalAlignment="Left"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" Margin="1" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </navigation:Page>
TrustedApplication/AccessFileSystem.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Navigation; using System.IO; namespace Silverlight50.TrustedApplication { public partial class AccessFileSystem : Page { public AccessFileSystem() { InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { if (!App.Current.IsRunningOutOfBrowser) { MessageBox.Show("请在OOB中运行"); LayoutRoot.Visibility = Visibility.Collapsed; } // Application.Current.HasElevatedPermissions - 判断 OOB 模式中的应用程序是否为被信任的应用程序 if (Application.Current.HasElevatedPermissions) { // 获取 C 盘的目录信息 DirectoryInfo root = new DirectoryInfo(@"C:\"); listBoxDirectory.ItemsSource = root.EnumerateDirectories(); listBoxFile.ItemsSource = root.EnumerateFiles(); } } } }
2、MultipleWindows(支持多窗口)
TrustedApplication/MultipleWindows.xaml
<navigation:Page x:Class="Silverlight50.TrustedApplication.MultipleWindows" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" d:DesignWidth="640" d:DesignHeight="480" Title="MultipleWindows Page"> <Grid x:Name="LayoutRoot" Background="White"> <Button Name="btn" Content="新开窗口" Click="btn_Click" /> </Grid> </navigation:Page>
TrustedApplication/MultipleWindows.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Navigation; namespace Silverlight50.TrustedApplication { /// <summary> /// 演示对多窗口的支持 /// </summary> public partial class MultipleWindows : Page { Random _random = new Random(); public MultipleWindows() { InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { if (!App.Current.IsRunningOutOfBrowser) { MessageBox.Show("请在OOB中运行"); LayoutRoot.Visibility = Visibility.Collapsed; } } private void btn_Click(object sender, RoutedEventArgs e) { // Application.Current.HasElevatedPermissions - 判断 OOB 模式中的应用程序是否为被信任的应用程序 if (Application.Current.HasElevatedPermissions) { /* * Window - OOB 模式下的应用程序窗口 * Height - 窗口的高 * Width - 窗口的宽 * Top - 窗口距顶部的距离 * Left - 窗口距左侧的距离 * Title - 窗口的标题 * Visibility - 窗口的可见性 * Content - 窗口的内容 * TopMost - 窗口是否显示在最前面 * IsActive - 是否为激活窗口(仅 get) * IsVisible - 窗口是否可见(仅 get) * WindowState - 窗口的状态(WindowState.Normal,WindowState.Minimized,WindowState.Maximized) * WindowStyle - 窗口的样式(WindowStyle.None,WindowStyle.SingleBorderWindow,WindowStyle.BorderlessRoundCornersWindow) * * Activate() - 激活窗口,使之具有焦点,并置于最前面 * Window.Close() - 关闭窗口 * * Closing - 窗口关闭前触发的事件 */ Window newWindow = new Window(); newWindow.Height = 400; newWindow.Width = 500; newWindow.Top = 1 + _random.Next(0, 100); newWindow.Left = 1 + _random.Next(0, 100); newWindow.Title = "新窗口"; newWindow.Visibility = Visibility.Visible; // 添加一个内部有按钮的 Canvas,设置 Canvas 的背景色为白色 Button btn = new Button(); btn.Width = 80.0; btn.Height = 30.0; btn.Content = "点 击"; btn.Margin = new Thickness(5, 10, 0, 0); btn.Click += new RoutedEventHandler(btn_Click); Canvas canvas = new Canvas(); canvas.Children.Add(btn); canvas.Background = new SolidColorBrush(Colors.White); newWindow.Content = canvas; newWindow.WindowState = WindowState.Normal; } } } }
3、In Browser(被信任的程序在浏览器中运行)
TrustedApplication/InBrowser.xaml
<navigation:Page x:Class="Silverlight50.TrustedApplication.InBrowser" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" d:DesignWidth="640" d:DesignHeight="480" Title="InBrowser Page"> <StackPanel x:Name="LayoutRoot" Orientation="Vertical" HorizontalAlignment="Left"> <HyperlinkButton TargetName="_blank" NavigateUri="http://msdn.microsoft.com/en-us/library/gg192793(v=vs.96).aspx" Content="如何使在浏览器中运行的程序成为被信任的程序(需要管理员介入)" /> </StackPanel> </navigation:Page>
4、Call Windows API
TrustedApplication/CallWindowsAPI.xaml
<navigation:Page x:Class="Silverlight50.TrustedApplication.CallWindowsAPI" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" d:DesignWidth="640" d:DesignHeight="480" Title="CallWindowsAPI Page"> <StackPanel x:Name="LayoutRoot"> <Button Content="C 盘的驱动器类型" Click="Button_Click" /> </StackPanel> </navigation:Page>
TrustedApplication/CallWindowsAPI.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Navigation; using System.Runtime.InteropServices; namespace Silverlight50.TrustedApplication { public partial class CallWindowsAPI : Page { public CallWindowsAPI() { InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { if (!App.Current.IsRunningOutOfBrowser) { MessageBox.Show("请在OOB中运行"); LayoutRoot.Visibility = Visibility.Collapsed; } } // 演示如何调用 Windows API [DllImport("kernel32.dll")] static extern int GetDriveType(string lpRootPathName); private void Button_Click(object sender, RoutedEventArgs e) { // Application.Current.HasElevatedPermissions - 判断 OOB 模式中的应用程序是否为被信任的应用程序 if (Application.Current.HasElevatedPermissions) { MessageBox.Show("C 盘的驱动器类型:" + GetDriveType(@"c:\")); } } // 注:非托管代码回调托管代码时,托管代码应加上 [AllowReversePInvokeCalls] 标记 } }
OK
[源码下载]
相关文章推荐
- javascript有个特殊的对象ActiveXObject,通过它可以访问windows的本地文件系统和应用程序
- javascript有个特殊的对象ActiveXObject,通过它可以访问windows的本地文件系统和应用程序
- 稳扎稳打Silverlight(45) - 4.0浏览器外运行(Out Of Browser)之被信任的应用程序(Trusted Application)
- Silverlight 4 本地文件系统访问支持
- 稳扎稳打Silverlight(45) - 4.0浏览器外运行(Out Of Browser)之被信任的应用程序(Trusted Application)
- 创建访问本地文件系统的信任APPLET(1)
- 创建访问本地文件系统的信任APPLET(2)
- 隐藏控制台程序运行时的窗口(Windows API ShowWindow的应用)
- “config.nt.系统文件不适用于运行MS-DOS与microsoft windows应用程序”
- 创建访问本地文件系统的信任APPLET(2)
- C:\Windows\system32\MSVCR100.dll 没有被指定在 Windows 上运行,或者它包含错误。请尝试使用原始安装媒体重新安装程序,或联系您的系统管理员或软件供应商以获取支持。【解决办法】
- windows7下,在命令窗口中用telnet命令时, 命令无法执行,提示:“'telnet' 不是内部或外部命令,也不是可运行的程序或批处理文件”
- android 怎样内置/预置/预编译文件(运行程序,应用程序,apk, jar, lib 等随意文件)到系统中
- [疑难杂症]系统文件不适用于运行MS-DOS与Microsoft Windows应用程序
- windows系统中的浏览器(支持html5的),用html5上传word文件获取到的file.type值为空,ios系统则能获取到
- 关于浏览器访问本地文件系统
- 32位程序访问64位Windows操作系统存放64位系统文件的 \Windows\System32 目录时将遇到重定向目录问题
- Windows系统下dos窗口运行程序出现中文乱码
- 创建访问本地文件系统的信任APPLET
- 本地打印后台处理程序服务没有运行和windows无法连接到打印机拒绝访问