我为爸爸创建了一个应用程序。它只是一个简单的听写程序。问题是,当他将它安装在他的计算机上时,它停滞不前,并说一般访问被拒绝错误。
第一次它给出了我使用SaveFileDialog sfd = new SaveFileDialog()
的错误,然后添加了通常' if语句"确保对话框没问题。但是该应用程序拒绝访问文件。
我对Environment.GetFolder
做了同样的事情,并将其安装在他的计算机上并运行正常。但是,当我使用工具栏中的saveFileDialog1
和openFileDialog1
时,它不会保存或打开txt文档。
它适用于我的笔记本电脑而不是他的笔记本电脑这可能是由于代码与他的计算机出错。另外,Environement.GetFolder
与SaveFileDialog
一起使用的正确方法是什么。
如果需要,我也可以将完整的代码发布到程序中。
private void lblOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "Open File";
open.Filter = "Text Files (*txt) | *.txt";
if (open.ShowDialog() == DialogResult.OK)
{
StreamReader read = new StreamReader(File.OpenRead(open.FileName));
txtTextBox.Text = read.ReadToEnd();
read.Dispose();
}
}
private void lblSaveFile_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Title = "Save File";
save.Filter = "Text Files (*txt) | *.txt";
if (save.ShowDialog() == DialogResult.OK)
{
StreamWriter write = new StreamWriter(File.Create(save.FileName));
write.Write(txtTextBox.Text);
write.Dispose();
}
}
这是我在屏幕录制器上使用的Enviroment
。我点击保存时会弹出一个对话框,我输入文件名按保存,它什么也没做。它保存文件但不是我指定的。所以我想合并上面和下面的代码。上面的代码不授予访问权限,但以下代码
string OutputPath;
OutputPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos) + @"\\IvanSoft Desktop Recorder" + saveFileDialog1;
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
string fileName = saveFileDialog1.FileName;
fileName = "Tutorial";
}
程序的整个代码
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Speech.Recognition;
using System.Threading;
namespace AGM_Speech
{
public partial class Form1 : Form
{
public SpeechRecognitionEngine recognizer;
public Grammar grammar;
public Thread RecThread;
public Boolean RecognizerState = true;
public Form1()
{
InitializeComponent();
}
private void lblAbout_Click(object sender, EventArgs e)
{
this.Hide();
About about = new About();
about.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
GrammarBuilder builder = new GrammarBuilder();
builder.AppendDictation();
grammar = new Grammar(builder);
recognizer = new SpeechRecognitionEngine();
recognizer.LoadGrammarAsync(grammar);
recognizer.SetInputToDefaultAudioDevice();
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
RecognizerState = true;
RecThread = new Thread(new ThreadStart(RecThreadFunction));
RecThread.Start();
}
private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (!RecognizerState)
return;
this.Invoke((MethodInvoker)delegate
{
txtTextBox.Text += (e.Result.Text.ToLower() + " ");
txtTextBox.SelectionStart = txtTextBox.Text.Length - 0;
txtTextBox.SelectionLength = 0;
});
}
public void RecThreadFunction()
{
while (true)
{
try
{
recognizer.RecognizeAsync();
}
catch
{
}
}
}
private void lblStartSpeech_Click(object sender, EventArgs e)
{
RecognizerState = true;
}
private void lblStopSpeech_Click(object sender, EventArgs e)
{
RecognizerState = false;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
RecThread.Abort();
RecThread = null;
grammar = null;
recognizer.UnloadAllGrammars();
recognizer.Dispose();
}
private void lblOpenFile_Click(object sender, EventArgs e)
{
string open = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
StreamReader reader = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
}
private void lblSaveFile_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Title = "Save File";
save.Filter = "Text Files (*txt) | *.txt";
if (save.ShowDialog() == DialogResult.OK)
{
StreamWriter write = new StreamWriter(File.Create(save.FileName));
write.Write(txtTextBox.Text);
write.Dispose();
}
}
private void txtSearch_Click(object sender, EventArgs e)
{
txtSearch.Clear();
lblGo_Click(null, null);
}
private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)ConsoleKey.Enter)
{
lblGo_Click(null, null);
}
}
private void lblGo_Click(object sender, EventArgs e)
{
int index = 0;
String temp = txtTextBox.Text;
txtTextBox.Text = "";
txtTextBox.Text = temp;
while (index <= txtTextBox.Text.LastIndexOf(txtSearch.Text))
{
txtTextBox.Find(txtSearch.Text, index, txtTextBox.TextLength, RichTextBoxFinds.None);
txtTextBox.SelectionColor = Color.YellowGreen;
index = txtTextBox.Text.IndexOf(txtSearch.Text, index) + 1;
}
}
}
}
答案 0 :(得分:0)
很难说你失败的地方,因为尝试/捕获或记录的方式并不多。
您可以使用它,并粘贴显示在消息框中的堆栈跟踪吗?
irb(main):001:0> BigDecimal.new("2.11")
SystemStackError: stack level too deep
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/xeroizer-2.16.4/lib/big_decimal_to_s.rb:4:in `to_s_with_default_format'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/big_decimal/conversions.rb:9:in `to_s'
... 10876 levels...
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sylar/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
irb(main):002:0>
有了这个,加上记录到Windows事件查看器的事件(开始&gt;运行&gt; Eventvwr&gt;安全性),我们应该能够告诉你问题是什么。
最后,如果您只提供要运行的可执行文件,则应检查该文件的属性,以确保它不会在Windows中被阻止。