A XAML browser application (XBAP) running in partial trust can safely upload files from a client machine. : Page « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » PageScreenshots 
A XAML browser application (XBAP) running in partial trust can safely upload files from a client machine.
A XAML browser application (XBAP) running in partial trust can safely upload files from a client machine.
  


<Page x:Class="SafeFileUploadPartialTrustSample.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="HomePage"
  xmlns:dialogs="clr-namespace:Microsoft.Win32;assembly=PresentationFramework">
    <StackPanel>
    <Button Name="uploadButton" Click="uploadButton_Click" Width="100">Upload Image...</Button>
    <Image Name="viewImage" Width="500" Height="300"></Image>
    <Label Name="nameLabel"></Label>
    
    </StackPanel>
</Page>
//File:Window.xaml.cs
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using Microsoft.Win32;

namespace SafeFileUploadPartialTrustSample {
    public partial class HomePage : Page, IProvideCustomContentState {
        public HomePage() {
            InitializeComponent();
        }

        void uploadButton_Click(object sender, RoutedEventArgs e) {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";

            if (dlg.ShowDialog() == true) {
                if (this.viewImage.Source != null) {
                    ImageCustomContentState iccs = new ImageCustomContentState(this.viewImage.Source, (string)this.nameLabel.Content);
                    this.NavigationService.AddBackEntry(iccs);
                }
                using (Stream stream = dlg.OpenFile()) {
                    BitmapDecoder bitmapDecoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    this.viewImage.Source = bitmapDecoder.Frames[0];
                    this.nameLabel.Content = dlg.SafeFileName;
                }
            }
        }
        public CustomContentState GetContentState() {
            return new ImageCustomContentState(this.viewImage.Source, (string)this.nameLabel.Content);
        }
    }
    [Serializable]
    public class ImageCustomContentState : CustomContentState
    {

        ImageSource imageSource;
        string filename;

        public ImageCustomContentState(ImageSource imageSource, string filename)
        {
            this.imageSource = imageSource;
            this.filename = filename;
        }

        public override string JournalEntryName
        {
            get return this.filename; }
        }

        public override void Replay(NavigationService navigationService, NavigationMode mode)
        {
            HomePage homePage = (HomePage)navigationService.Content;
            homePage.viewImage.Source = this.imageSource;
            homePage.nameLabel.Content = this.filename;
        }
    }
}

   
    
  
Related examples in the same category
1.Page Loaded eventPage Loaded event
2.Remember and navigate through multiple sets of state for a single page instanceRemember and navigate through multiple sets of state for a single page instance
3.Navigate to an instance of a custom class, instead of a Page.Navigate to an instance of a custom class, instead of a Page.
4.Create a button when the page loads.Create a button when the page loads.
5.UI With Page for Dynamic Button contentUI With Page for Dynamic Button content
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.