我可以保存一个文件而不另存为对话框吗?用saveas对话框保存文件?
-1
A
回答
1
你提的问题是非常模糊的,但服用野生刺吧:
是的,只是使用的类在System.IO
namespace。例如,在FileStream
class documentation中有一个例子;引用它:
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
//Create the file.
using (FileStream fs = File.Create(path))
{
AddText(fs, "This is some text");
AddText(fs, "This is some more text,");
AddText(fs, "\r\nand this is on a new line");
AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n");
for (int i=1;i < 120;i++)
{
AddText(fs, Convert.ToChar(i).ToString());
}
}
//Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
}
private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
@All:同样,这是从文档引用,而不是原始代码。
1
当然。您可以使用StreamWriter类:
FileInfo t = new FileInfo("f.txt");
StreamWriter Tex =t.CreateText();
Tex.WriteLine("Hello");
Tex.close();
1
是的,请查看File类。
3
是的,但你必须有一个文件名。文件对话框仅用于确定写入文件的好文件名。
2
当然,如果你知道你想保存的路径。
您可以使用System.IO.File的方法,如WriteAllBytes,WriteAllLines或WriteAllText。
相关问题
- 1. 保存文件不使用保存文件对话框
- 2. 挂钩保存文件对话框
- 3. jquery文件保存为对话框
- 4. 文件打开/保存对话框
- 5. C#保存文件对话框错误
- 6. 打开并保存文件对话框
- 7. 在Jquery中保存文件对话框
- 8. 文件打开/保存对话框
- 9. 保存没有对话框的文件
- 10. MFC保存文件对话框
- 11. 保存文件用的JFileChooser保存对话框
- 12. 使用保存对话框保存已创建的XML文件
- 13. 保存对话框
- 14. 如何指定Excel文件SaveAs对话框的默认目录?
- 15. Word Interop 12:SaveAs新的文件名没有对话框
- 16. 无法保存对话框保存文件
- 17. 保存为对话框保存PDF文件
- 18. 打开并保存文件,不保存/打开对话框
- 19. 与对话保存文件
- 20. 如何在C#中使用保存对话框保存ASCII文本文件?
- 21. 如何在使用保存文件对话框保存文件时输入无效文件名的消息框
- 22. 在Python3中使用通用对话框保存文件
- 23. 从文件保存对话框返回文件名(windows32)
- 24. 保存资源对话框
- 25. 打开/保存对话框
- 26. 保存对话框输入
- 27. 使用webclient下载文件与保存对话框
- 28. 是否可以使用JavaScript生成保存文件对话框?
- 29. 如何使用保存对话框下载文件
- 30. 使用PowerShell/C#从cmd批保存文件对话框
有或没有? – Bolu 2010-11-22 12:56:13
实际上,“另存为”对话框与*保存*(创建/写入/覆盖/附加)文件的行为很少有关。 – Ani 2010-11-22 12:57:41