zoukankan      html  css  js  c++  java
  • C#三个平台上的文件选择方法

    wpf:

    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
    dlg.DefaultExt = ".txt";
    Nullable<bool> result = dlg.ShowDialog();
    if (result == true)
    {
           // Open document 
           string filename = dlg.FileName;
    }    
    FileStream aFile = new FileStream(filename, FileMode.Open);
                StreamReader sr = new StreamReader(aFile);

    需要 using System.Windows.Documents; using System.IO;

    windows app:

    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.ViewMode = PickerViewMode.List;
    openPicker.SuggestedStartLocation
    = PickerLocationId.Desktop;
    openPicker.FileTypeFilter.Add(
    ".txt"); ss.file = await openPicker.PickSingleFileAsync();
    string filename =ss.file.Path;
    StorageFile file =ss.file;
    var fl = await FileIO.ReadLinesAsync(file);

    需要:

    using Windows.Storage;
    using Windows.Storage.Pickers;
    using System.Collections;

    Windows phone:

    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.ViewMode = PickerViewMode.List;
    openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
    openPicker.FileTypeFilter.Add(".txt");
    openPicker.PickSingleFileAndContinue();
    void MainPage_Activated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args)
    {
                FileOpenPickerContinuationEventArgs continueArgs = args as FileOpenPickerContinuationEventArgs;
                if (continueArgs != null)
                {
                    ss.file = continueArgs.Files[0];
                    if (ss.file != null)
                    {
                        BlankPage1 pg1 = new BlankPage1();
                        ss.bl = true;
                        Frame.Navigate(typeof(BlankPage1));
                    }
                    else
                    {
    
                    }
                }
    }
    string filename = MainPage.ss.file.Path;
    StorageFile file = MainPage.ss.file;
    var fl = await FileIO.ReadLinesAsync(file);

    需要:


    using Windows.Storage;
    using Windows.Storage.Pickers;
    using Windows.ApplicationModel.Core;
    using Windows.ApplicationModel.Activation;

    using System.Collections;

  • 相关阅读:
    2018-2-26 php、mysql数据库制作简单的商城购物车
    2018-2-8 租房信息的增删改和搜索
    2018-2-6 留言板的制作
    ztree连接数据库问题总结
    织梦cms
    MySQLDB.class.php
    类和对象
    构造、析构;重写;设计模式;单例;抽象;重载
    类、面向对象、类的继承
    css 区块与盒子模型
  • 原文地址:https://www.cnblogs.com/wos1239/p/4527600.html
Copyright © 2011-2022 走看看