我有这个文件类型过滤器:
public const string Png = "PNG Portable Network Graphics (*.png)|" + "*.png";
public const string Jpg = "JPEG File Interchange Format (*.jpg *.jpeg *jfif)|" + "*.jpg;*.jpeg;*.jfif";
public const string Bmp = "BMP Windows Bitmap (*.bmp)|" + "*.bmp";
public const string Tif = "TIF Tagged Imaged File Format (*.tif *.tiff)|" + "*.tif;*.tiff";
public const string Gif = "GIF Graphics Interchange Format (*.gif)|" + "*.gif";
public const string AllImages = "Image file|" + "*.png; *.jpg; *.jpeg; *.jfif; *.bmp;*.tif; *.tiff; *.gif";
public …Run Code Online (Sandbox Code Playgroud) 我似乎对我的文件选择器对话的非常简单的实现有一个问题,这需要我每次都要最小化Netbeans才能到达它,并且特别是现在通过测试它变得非常令人沮丧.
我已经在网上看到了一些解决方案,包括SO,但似乎没有一个可以做到这一点,而其他一些解决方案对我目前的水平看起来非常冗长和复杂.
private void fileSearch() {
JFileChooser fileSelect = new JFileChooser();
int returnVal = fileSelect.showOpenDialog(null);
String pathToFile;
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileSelect.getSelectedFile();
pathToFile = file.getAbsolutePath();
try {
P.binaryFileToHexString(pathToFile);
} catch (Exception e) {
System.out.print("Oops! there was an error there..." + e);
}
System.out.println("\nYou chose to open this file: " + file.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
我的一些尝试包括使用;
.requestFocus();
.requestFocusInWindow();
.setVisible();
Run Code Online (Sandbox Code Playgroud)
我可以设置一个特定的属性/方法来解决问题吗?
我在c#中使用打开的文件对话框时发现了一个奇怪的行为.
如果在Windows XP当前工作目录中使用此代码更改为所选文件的路径,则如果在Windows 7当前工作目录中运行此代码不会更改.
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(string.Format("Current Directory {0}",Directory.GetCurrentDirectory()), "My Application",MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog and get result.
if (result == DialogResult.OK)
{
}
MessageBox.Show(string.Format("Current Directory {0}", Directory.GetCurrentDirectory()), "My Application", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
Run Code Online (Sandbox Code Playgroud)
有人知道这种行为的原因吗?为什么当前目录在XP中更改而不在Windows 7?
这基本上和简化了我现在拥有的:
<style>
form.noshow { height: 0; overflow: hidden; }
</style>
<form class=noshow target="SomeIframeThatExists">
<input type=file id=uf>
</form>
<a id=uflink href="/user/photo">Upload photo</a>
<script>
$('uf').addEvent('change', function(e) {
// alert('oele'); // this would work fine
this.form.submit(); // auch in IE > "Access denied" exception
});
$('uflink').addEvent('click', function(e) {
$('uf').click(); // opens file dialog in all browsers inc IE
return false;
});
</script>
Run Code Online (Sandbox Code Playgroud)
它在Chrome 11和FF 4中的作用(完美):
非常高科技和甜蜜.
在IE中,所有这些都有效,除了[6].表格未提交.Javascript错误:"访问被拒绝".无论表单如何不可见,只要打开对话框input.click(),表单就无法提交更改.(onchange函数执行正常.只有在form.submit()调用时才会出现错误.)
现在所有这一切我都能接受.IE糟透了.我和它一起生活.
到目前为止,我的解决方案是检查navigator"MSIE",然后单击链接而不是打开对话框,显示表单(带文件输入).然后用户必须单击实际的,丑陋的文件输入,然后一切正常.但丑陋.
问题有两个: …
为什么OpenFileDialog会改变我的工作目录?我应该假设System.Windows.Forms中的许多func会改变我的工作目录吗?
OpenFileDialog open = new OpenFileDialog();
open.Filter = filter;
a = Directory.GetCurrentDirectory(); //<-- correct
if (open.ShowDialog() == DialogResult.OK) //-- select a file on my desktop
{
a = Directory.GetCurrentDirectory(); //<-- incorrect, is set to my desktop
Run Code Online (Sandbox Code Playgroud) 我正在使用c#中的OpenFileDialog打开一个文件,我注意到加载文件并清除对话框需要20-40秒.
这是我的示例代码:
private void btnOpen_Click(object sender, EventArgs e)
{
if (ofdSettings.ShowDialog() == DialogResult.OK)
{
// do nothing
}
}
Run Code Online (Sandbox Code Playgroud)
即使使用这个有限的示例,对话框也需要20-40秒的持续时间才能清除.我正在选择的文件是一个只有1.36kb大的xml文件
我使用Microsoft的CommonOpenFileDialog来允许用户选择文件夹,但是当对话框出现时没有文件可见.当IsFolderPicker设置为true 时,是否可以显示文件和文件夹?
我目前的代码看起来像这样
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
SelectedFolderPath = dialog.FileName;
}
Run Code Online (Sandbox Code Playgroud) 是否可以指定自定义过滤器,如'ABC*.pdf',这意味着:"显示所有以ABC开头的PDF"?
我只能指定*.pdf,*.doc , . 等
谢谢弗洛里安
我觉得很容易找到,我错了.
对话要求:
对话框首选项:
我在WEB上尝试过几个例子,没有一个满足所有要求!
一些最接近解决方案的例子:
有没有选择在C#中选择文件夹?
最理想的是,我想使用OpenFileDialog来选择文件夹,或者至少使用类似的东西.
openfiledialog ×10
c# ×7
.net ×4
winforms ×3
directory ×1
file-upload ×1
filefilter ×1
filter ×1
java ×1
javascript ×1
jfilechooser ×1
swing ×1