gpt4 book ai didi

c# - "The given path' s 格式不受支持”

转载 作者:行者123 更新时间:2023-12-03 03:11:27 24 4
gpt4 key购买 nike

这是我的第一个问题,英语不是我的母语,所以请全面地回答我。

基本上我的程序将数据保存在 .js 文件中。我使用 SaveFileDialog 方法设置路径并使用 .FileName 设置...文件名。我是这样做的

private void parcourir_Click(object sender, EventArgs e)
{
SaveFileDialog exportJSFile = new SaveFileDialog();

// Getting year, month and day of the day to generate the file name
DateTime date = DateTime.Today;

exportJSFile.FileName = date.Year + "_" + date.Month + "_" + date.Day + "_ct.js";
if (exportJSFile.ShowDialog() == DialogResult.OK)
{
this.JSfilePath.Text = exportJSFile.FileName;
}
}

然后我使用 StreamWriter 将数据写入我的文件

// Writing the first block (header) of data into the .js file
System.IO.StreamWriter objWriterFirstBlock;
objWriterFirstBlock = new System.IO.StreamWriter(@JSfilePath.ToString());
objWriterFirstBlock.Write(firstBlock);
objWriterFirstBlock.Close();

当我调试它时,我收到来自此行的上述错误消息:

objWriterFirstBlock = new System.IO.StreamWriter(@JSfilePath.ToString());

我尝试了相同的命令,但没有@,结果相同。当我使用对话框设置路径名时,路径显示在文本框中,看起来是正确的。当我在调试器中检查 JSfilePath.ToString() 的值时,它显示如下路径:

@JSfilePath = {Text = "C:\\Users\\admin\\Documents\\2014_3_5_ct.js"}

谁能告诉我出了什么问题

最佳答案

假设 JSfilePath 是一个 TextBox,看来您正在 TextBox 上使用 ToString() 方法code> 本身,它不会返回您正在寻找的内容。

如果您将其更改为 JSfilePath.Text 这应该会为您修复:

objWriterFirstBlock = new System.IO.StreamWriter(JSfilePath.Text);

关于c# - "The given path' s 格式不受支持”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207442/

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