本文整理汇总了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;
}
示例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);
}
}
}