本文整理汇总了C#中System.Windows.Controls.OpenFileDialog类的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog类的具体用法?C# OpenFileDialog怎么用?C# OpenFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenFileDialog类属于System.Windows.Controls命名空间,在下文中一共展示了OpenFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnAdd_Click
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = GlobalMembers.SupportedFileType;
dlg.FilterIndex = 1;
dlg.Multiselect = false;
if ((bool)dlg.ShowDialog())
{
foreach (UploadItem ui in listUploadItems.Items)
{
if (ui.ItemInfo.Name == dlg.File.Name)
return;
}
int itemId = listUploadItems.Items.Count;
if (itemId < GlobalMembers.MaxThread)
{
UploadItem item = new UploadItem(dlg.File, itemId);
listUploadItems.Items.Add(item);
if (IsSignIn && !btnUpload.IsEnabled)
btnUpload.IsEnabled = true;
}
}
}
示例2: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog nekaj = new OpenFileDialog();
bool? nekaj2 = nekaj.ShowDialog();
if (nekaj2 == true)
{
using (FileStream fs = nekaj.File.OpenRead())
{
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
char[] niz = new char[buffer.Length];
for (int i = 0; i < buffer.Length; i++)
niz[i] = (char)buffer[i];
IsolatedStorageFile isf =
IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream tok = new IsolatedStorageFileStream("test.txt", FileMode.Create, isf);
tok.Write(buffer, 0, buffer.Length);
tok.Close();
}
}
else MessageBox.Show("Preklicano");
}
示例3: OpenFile
private void OpenFile(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog()
{
Filter = "图片 (*.jpg)|*.jpg",
Multiselect = false //不允许多选
};
bool chooseFile = dialog.ShowDialog() == true;
if (!chooseFile) { return; }
cover.CanSee = true;
Stream tStream = dialog.File.OpenRead();
byte[] t = new byte[tStream.Length];
tStream.Read(t, 0, (int)tStream.Length);
PicServiceClient client = new PicServiceClient();
client.UploadCompleted += (_sender, _e) =>
{
State = _e.Result;
cover.CanSee = false;
hadOpenFile = true;
};
client.UploadAsync(t);
Stream ts = new MemoryStream(t);
BitmapImage bi = new BitmapImage();
bi.SetSource(ts);
img.ImageSource = bi;
}
示例4: OnClick
private void OnClick(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = true;
if (dlg.ShowDialog() == true)
{
if (MessageBox.Show("Are you sure you want to upload the selected files?", "Confirm Upload", MessageBoxButton.OK) == MessageBoxResult.OK)
{
//string cmd = "test";
//string msg = "test";
//string url = "https://secure.veshter.com/static/bulkupload/test/dummyack.php";
string url = "http://localhost:7777/BulkUploaderTestPage.html";
VESHTER.HttpHelper helper = new VESHTER.HttpHelper(url);//, "POST",
//new KeyValuePair<string, string>("authKey", "key"),
//new KeyValuePair<string, string>("cmd", cmd.ToString()),
//new KeyValuePair<string, string>("msg", msg));
//helper.ResponseComplete += new VESHTER.HttpResponseCompleteEventHandler(this.CommandComplete);
//helper.Execute();
//foreach (System.IO.FileInfo info in dlg.Files)
//{
// post.Post();
//}
}
}
}
示例5: BtnBrowseImage_Click
private void BtnBrowseImage_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Multiselect = false, //Filter = "Jpeg Files (*.jpg)|*.jpg|All Files(*.*)|*.*",
Filter = "JPEG Images (*.jpeg *.jpg)|*.jpeg;*.jpg|Png Images (*.png)|*.png",
};
if (ofd.ShowDialog() == true)
{
try
{
LoadingInfo.Visibility = System.Windows.Visibility.Visible;
focusRectangle.Viewport.Visibility = System.Windows.Visibility.Collapsed;
focusRectangle.LoadImageStream(ofd.File.OpenRead(), ZoomInOut);
fileInfo = ofd.File;
BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = false;
ZoomInOut.IsEnabled = true;
System.Threading.Timer timer = new System.Threading.Timer(TimerCallback,
new LoadingState()
{
focusRectangle = focusRectangle,
LoadingInfo = LoadingInfo,
BtnUploadImage = BtnUploadImage,
BtnAdvanceMode = BtnAdvanceMode
} as object,
1000, 500);
}
catch (Exception exception)
{
Utils.ShowMessageBox("文件无效:" + exception.Message);
ZoomInOut.IsEnabled = false;
BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = false;
}
}
}
示例6: btnFile2_Click
private void btnFile2_Click(object sender, RoutedEventArgs e)
{
try
{
var dialog = new OpenFileDialog { Multiselect = false };
if (dialog.ShowDialog() == true)
{
using (var stream = dialog.File.OpenRead())
{
StreamReader sr = new StreamReader(stream, new Gb2312Encoding());
strDst = sr.ReadToEnd();
// 删除多余的换行
strDst = strDst.Replace("\0", "");
if (!string.IsNullOrEmpty(strDst))
CompareFile();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例7: SilverlightLoadModelDialog
public SilverlightLoadModelDialog()
{
_loadFileDialog = new OpenFileDialog
{
Filter = "Turtle Pictures (.tur)|*.tur",
};
}
示例8: View_SetFocus
private void View_SetFocus(object sender, EventArgs e)
{
try
{
if (sender is int)
{
switch (Convert.ToInt32(sender))
{
case 0:
OpenFileDialog op = new OpenFileDialog();
op.Filter = "Excel xml (*.xml)|*.xml";
if (op.ShowDialog() == true)
{
if (this.DataContext is UploadSubjectViewModel)
{
(this.DataContext as UploadSubjectViewModel).OnGetFileClickComplete(op.File);
}
}
break;
}
}
if (sender is List<CustomizeSubjectType>)
{
Telerik.Windows.Controls.GridViewComboBoxColumn col = rgvData.Columns["type"] as Telerik.Windows.Controls.GridViewComboBoxColumn;
if (col != null)
{
col.ItemsSource = sender as List<CustomizeSubjectType>;
}
}
}
catch (Exception ex)
{
MessageCustomize.Show(ex.Message);
}
}
示例9: Browse
private async void Browse()
{
var dlg = new OpenFileDialog
{
Multiselect = false,
Filter = "JPEG Images (*.jpg, *.jpeg)|*.jpg;*.jpeg"
};
if (dlg.ShowDialog() == true)
{
var file = dlg.File;
var progress = new ProgressWindow { Content = "Закачиваем файл..." };
progress.Show();
var task = await filesRepository.Create(file.OpenRead(), file.Name, "image/jpeg");
if (task.Succeed)
{
var fileId = task.Result;
var task2 = await productsRepository.AttachFile(productId, fileId);
if (task2.Succeed)
{
await LoadFiles();
}
}
progress.Close();
}
}
示例10: btnOpenLog_Click
private void btnOpenLog_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Log Files (.log)|*.log|All Files (*.*)|*.*";
dlg.FilterIndex = 1;
bool? userClickedOK = dlg.ShowDialog();
// Process input if the user clicked OK.
if (userClickedOK == true)
{
grdLog.ItemsSource = null;
// Open the selected file to read.
System.IO.Stream fileStream = dlg.File.OpenRead();
using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
{
try
{
Log.Instance.InitializeFromStream(reader);
}
catch (Exception ex)
{
MessageBox.Show("There was an error reading this log file. { " + ex.StackTrace + " }");
}
}
fileStream.Close();
grdLog.ItemsSource = Log.Instance.Items;
}
}
示例11: SelectFilesButton_Click
/// <summary>
/// 选择文件对话框事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SelectFilesButton_Click(object sender, RoutedEventArgs e)
{
var ofd = new OpenFileDialog {Multiselect = true};
try
{
if (!string.IsNullOrEmpty(_fileFilter))
ofd.Filter = _fileFilter;
}
catch (ArgumentException ex)
{
//User supplied a wrong configuration file
throw new Exception("Wrong file filter configuration.", ex);
}
if (ofd.ShowDialog() != true) return;
foreach (var file in ofd.Files)
{
var userFile = new UploadFile
{
FileName = file.Name,
FileStream = file.OpenRead()
};
if (userFile.FileStream.Length <= _maxFileSize)
{
//向文件列表中添加文件信息
_files.Add(userFile);
}
else
{
MessageBox.Show( "Maximum file size is: " + (_maxFileSize/1024) + "KB.");
}
}
}
示例12: BrowseButton_Click
/// <summary>
/// Browse button
/// </summary>
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
// Limit the dialog to only show ".csv" files,
// modify this as necessary to allow other file types
openFileDialog.Filter = "xml (*.xml)|*.xml";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect = true;
documentStream = new List<FileStream>();
if (openFileDialog.ShowDialog() == true)
{
foreach (FileInfo file in openFileDialog.Files)
{
this.FileTextBox.Text += file.Name + ",";
System.IO.FileStream myStream = file.OpenRead();
documentStream.Add(myStream);
}
this.FileTextBox.IsReadOnly = true;
}
}
示例13: PromptForParts
public void PromptForParts(Action<IEnumerable<ComposablePartCatalog>> callback)
{
if (callback != null)
{
List<ComposablePartCatalog> catalogs = new List<ComposablePartCatalog>();
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "XAPs (*.xap)|*.xap";
dialog.Multiselect = false;
if (dialog.ShowDialog() == true)
{
var fileStream = dialog.File.OpenRead();
var assemblies = Package.LoadPackagedAssemblies(fileStream);
AggregateCatalog catalog = new AggregateCatalog();
CatalogHelper.DiscoverParts(catalog, assemblies);
catalogs.Add(catalog);
}
callback(catalogs);
}
}
示例14: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "JPEG / PNG (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png";
if (openDialog.ShowDialog().GetValueOrDefault(false))
{
using (FileStream stream = openDialog.File.OpenRead())
{
wb = ImageHelper.GetImageSource(stream, 700, 700);
}
//byte[] buffer;
//using (
Stream Source = JpgEncoder.Encode(wb, 85); //)
{
//int bufferSize = Convert.ToInt32(Source.Length);
//buffer = new byte[bufferSize];
//Source.Read(buffer, 0, bufferSize);
//Create a new UserFile object
_file.FileName = openDialog.File.Name;
_file.FileStream = Source;
//userFile.UIDispatcher = this.Dispatcher;
_file.UploadContainerUrl = _uploadContainerUrl;
_file.Upload(null);
//Source.Close();
}
}
}
示例15: Open
public IEnumerable<IResult> Open()
{
var dialog = new OpenFileDialog();
yield return Show.OpenFileDialog(dialog);
yield return Show.MessageBox("You opened " + dialog.File.Name + ".", "File");
}