本文整理汇总了C#中Microsoft.Win32.OpenFileDialog.OpenFiles方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.OpenFiles方法的具体用法?C# OpenFileDialog.OpenFiles怎么用?C# OpenFileDialog.OpenFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.OpenFiles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryLoadImage
public ImageViewModel TryLoadImage()
{
OpenFileDialog fileDialog = new OpenFileDialog()
{
CheckFileExists = true,
CheckPathExists = true,
Multiselect = true,
Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png"
};
Func<string, bool> isValidFile = file =>
{
string[] extensions =
{
".jpg",
".png",
".jpeg"
};
string ext = Path.GetExtension(file);
return extensions.Contains(ext);
};
fileDialog.FileOk += (sender, args) =>
{
if (!fileDialog.FileNames.All(isValidFile))
args.Cancel = true;
};
bool? dialogResult = fileDialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
try
{
Stream[] files = fileDialog.OpenFiles();
for (int i = 0; i < fileDialog.FileNames.Length; i++)
{
string filePath = fileDialog.FileNames[i];
Stream file = files[i];
byte[] fileData = null;
using (var stream = new MemoryStream())
{
file.CopyTo(stream);
fileData = stream.ToArray();
}
ImageViewModel viewModel = new ImageViewModel(0, Path.GetFileName(filePath), fileData);
return viewModel;
}
}
catch (Exception ex)
{
}
}
return null;
}
示例2: AddItems
/// <summary>
/// Adds the items.
/// </summary>
/// <param name="files">The files.</param>
private void AddItems(OpenFileDialog files)
{
Stream[] fileStreams = files.OpenFiles();
for (int index = 0; index < files.FileNames.Length; index++)
{
Gallery gallery = ((Gallery)galleryListBox.SelectedItem);
ClientImage image = new ClientImage
{
ImageName = TruncatePath(files.FileNames[index]),
GalleryName = gallery.Name,
GalleryId = gallery.GalleryID,
PhotoBytes = GetByteArrayFromStream(fileStreams[index])
};
uploadListBox.Items.Add(image);
}
}
示例3: OpenFile_Click
private void OpenFile_Click(object sender, RoutedEventArgs e)
{
filePath.Clear(); textBox_Files.Text = "";
StringBuilder sb = new StringBuilder();
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true;
dialog.Filter = "Text Files (.txt)|*.txt";
dialog.ShowDialog();
if (dialog.OpenFiles() != null)
{
filePath.AddRange(dialog.FileNames);
sb.AppendLine("(" + filePath.Count + "шт.) ");
for (int i = 0; i < filePath.Count; i++)
{
sb.AppendLine(System.IO.Path.GetFileName(filePath[i]));
}
textBox_Files.Text = sb.ToString();
}
}
示例4: AddPatterns
private void AddPatterns()
{
OpenFileDialog fileDialog = new OpenFileDialog()
{
CheckFileExists = true,
CheckPathExists = true,
Multiselect = true,
Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg"
};
Func<string, bool> isValidFile = file =>
{
string[] extensions =
{
".png",
".jpeg",
".jpg"
};
string ext = Path.GetExtension(file);
return extensions.Contains(ext);
};
fileDialog.FileOk += (sender, args) =>
{
if (!fileDialog.FileNames.All(isValidFile))
args.Cancel = true;
};
bool? dialogResult = fileDialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
try
{
Stream[] files = fileDialog.OpenFiles();
for (int i = 0; i < fileDialog.FileNames.Length; i++)
{
string filePath = fileDialog.FileNames[i];
Stream file = files[i];
byte[] fileData = null;
using (var stream = new MemoryStream())
{
file.CopyTo(stream);
fileData = stream.ToArray();
}
CheckablePatternDataViewModel viewModel = new PatternDataViewModel(Path.GetFileName(filePath), Pattern.PatternType, fileData)
.ToCheckable(ItemState.Added);
Children.Add(viewModel);
}
}
catch (Exception ex)
{
}
CheckItem();
}
}