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

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Page 
24.69.6.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;
        }
    }
}
WPF A X A M L Browser Application X B A P Running In Partial Trust Can Safely Upload Files From A Client Machine
24.69.Page
24.69.1.Page Loaded eventPage Loaded event
24.69.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
24.69.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.
24.69.4.Create a button when the page loads.Create a button when the page loads.
24.69.5.UI With Page for Dynamic Button contentUI With Page for Dynamic Button content
24.69.6.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.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.