当前位置: 首页>>代码示例>>C#>>正文


C# OpenFileDialog.ShowReadOnly属性代码示例

本文整理汇总了C#中System.Windows.Forms.OpenFileDialog.ShowReadOnly属性的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.ShowReadOnly属性的具体用法?C# OpenFileDialog.ShowReadOnly怎么用?C# OpenFileDialog.ShowReadOnly使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.OpenFileDialog的用法示例。


在下文中一共展示了OpenFileDialog.ShowReadOnly属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenFile

private FileStream OpenFile()
{
    // Displays an OpenFileDialog and shows the read/only files.

    OpenFileDialog dlgOpenFile = new OpenFileDialog();
    dlgOpenFile.ShowReadOnly = true;

    if(dlgOpenFile.ShowDialog() == DialogResult.OK)
    {

        // If ReadOnlyChecked is true, uses the OpenFile method to
        // open the file with read/only access.
        string path = null;

        try {
            if(dlgOpenFile.ReadOnlyChecked == true)
            {
                return (FileStream)dlgOpenFile.OpenFile();
            }

            // Otherwise, opens the file with read/write access.
            else
            {
                path = dlgOpenFile.FileName;
                return new FileStream(path, System.IO.FileMode.Open,
                            System.IO.FileAccess.ReadWrite);
            }
        } catch (SecurityException ex)
            {
                // The user lacks appropriate permissions to read files, discover paths, etc.
                MessageBox.Show("Security error. Please contact your administrator for details.\n\n" +
                    "Error message: " + ex.Message + "\n\n" +
                    "Details (send to Support):\n\n" + ex.StackTrace
                );
            }
            catch (Exception ex)
            {
                // Could not load the image - probably related to Windows file system permissions.
                MessageBox.Show("Cannot display the image: " + path.Substring(path.LastIndexOf('\\'))
                    + ". You may not have permission to read the file, or " +
                    "it may be corrupt.\n\nReported error: " + ex.Message);
            }
    }

    return null;
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:46,代码来源:OpenFileDialog.ShowReadOnly

示例2: Main

//引入命名空间
using System;
using System.Windows.Forms;

public class OpenFileDialogSetFiles
{
  public static void Main() 
  {
    OpenFileDialog dlgOpen = new OpenFileDialog();
    
    dlgOpen.Title = "Select one or more files";
    dlgOpen.ShowReadOnly = true;
    dlgOpen.Multiselect = true;

    if (dlgOpen.ShowDialog() == DialogResult.OK)
    {
      foreach (string s in dlgOpen.FileNames)
        Console.WriteLine(s);
    }
  }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:21,代码来源:OpenFileDialog.ShowReadOnly


注:本文中的System.Windows.Forms.OpenFileDialog.ShowReadOnly属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。