Opening a Local File from a Silverlight Application : File « Data « Silverlight






Opening a Local File from a Silverlight Application

Opening a Local File from a Silverlight Application
 

<UserControl x:Class='SilverlightApplication3.MainPage'
    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' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
  <StackPanel>
    <Button Height="28.9" HorizontalAlignment="Stretch" Margin="8,8,11,0" VerticalAlignment="Top" Width="81.8" Content="Select Files" d:LayoutOverrides="Height" x:Name="ButtonSelectFiles" Click="ButtonSelectFiles_Click"/>
    <TextBlock Margin="4,2,2,2" Text="Status" TextWrapping="Wrap" x:Name="StatusTextBlock"/>
    <Border Margin="0,0,0,0" CornerRadius="12">
      <Border.Background>
        <LinearGradientBrush EndPoint="0.9,0" StartPoint="0,2">
          <GradientStop Color="#FF1D351E"/>
          <GradientStop Color="#FF1D351E" Offset="1"/>
          <GradientStop Color="#FFB7D8BA" Offset="0.5"/>
        </LinearGradientBrush>
      </Border.Background>
      <ListBox x:Name="FileList" Foreground="#FF000000" Height="217" Width="236" Opacity="1"/>
    </Border>
  </StackPanel>
</UserControl>

//File: Page.xaml.cs
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace SilverlightApplication3
{
  public partial class MainPage : UserControl
  {
    public MainPage()
    {
      InitializeComponent();
    }

    private void ButtonSelectFiles_Click(object sender, RoutedEventArgs e)
    {
      OpenFileDialog fileDlg = new OpenFileDialog();
      fileDlg.Filter = "Tiff Files (*.tif)|*.tif|All Files (*.*)|*.*";
      fileDlg.FilterIndex = 1;
      fileDlg.Multiselect = true;
      if (true == fileDlg.ShowDialog())
      {
        StatusTextBlock.Text = fileDlg.Files.Count() + " file(s) selected";
        foreach (var file in fileDlg.Files)
        {
          FileList.Items.Add(file.Name);
        }
      }
    }
  }
}

   
  








Related examples in the same category

1.Accessing the Isolated Local StorageAccessing the Isolated Local Storage