• 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;

  • 相关阅读:
    saveField方法
    cake使用事务的方法
    css 中引用css的方法
    一次标准的关联查询
    try cath用处
    使用其他模型分页$data = $this>paginate('MerchantProductOrder');
    jquery 常用代码
    php 邮箱验证原理
    cake 分页一个典型的条件
    一次典型的查询
  • 原文地址:https://www.cnblogs.com/wos1239/p/4527600.html
Copyright © 2020-2023  润新知