gpt4 book ai didi

C#文件夹浏览器对话框问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:33 26 4
gpt4 key购买 nike

我有一个按钮,单击后使用 stremReader 读取文本文件,并使用文件夹浏览器对话框保存文件。保存文件并再次单击按钮后,我收到一条错误消息,提示找不到文本文件,它会尝试从上一个文档的保存路径读取文本文件。

有什么办法可以解决这个问题吗?

部分代码如下:

private void Invoice_Load(object sender, EventArgs e)
{
try
{
StreamReader sr = new StreamReader(@"../../DatabasePath");
dataBase = sr.ReadLine();

if (dataBase == null)
{
MessageBox.Show("Please use this to choose the location of the database.");
Process.Start(@"..\..\DatabaseChooser.exe");
ready = false;
}

if (!ready)
{
while (IsProcessOpen("DatabaseChooser"))
{
ready = false;
}
ready = true;

if (ready)
{
doIfReady();
}
}

else if (ready)
{
doIfReady();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void btnCreateInvoice_Click(object sender, EventArgs e)
{
int SelectColumnIndex = 5;

foreach (DataGridViewRow row in dataGridViewInvoice.Rows)
{
if (row.Cells[SelectColumnIndex].Value != null &&
Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.OwningColumn.Index != SelectColumnIndex)
{
data += (cell.Value + " "); // do some thing
}
}
data += System.Environment.NewLine;
total += (int)row.Cells["TotPrice"].Value;
}
}

MessageBox.Show("Please choose your invoice template", "Template");
OpenFileDialog op = new OpenFileDialog();
op.ShowHelp = true;
op.Filter = "Microsoft Word Documents 97-2003 (*.doc)|*.doc|Microsoft Word 2007 (*.docx)|*.docx";
if (op.ShowDialog() == DialogResult.Cancel)
{
this.Hide();
}

MessageBox.Show("Please choose where you want to save the invoice", "Save");
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.Description = "Please choose";
if (fd.ShowDialog() == DialogResult.Cancel)
{
this.Hide();
}

string path = fd.SelectedPath + "\\" + txtFileName.Text + ".doc";

CreateWordDoc(op.FileName, path);
}

最佳答案

首先,您可能想发布一些代码。其次,你应该使用 SaveFileDialog保存文件而不是 FolderBrowser。

关于C#文件夹浏览器对话框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5744721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com