如何以不同的格式保存文件?
我有一个简单的问题,如何以不同的格式保存文件,例如“另存为”,
到目前为止我得到了这个
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
//this saves the file as a text or richtext.
saveFileDialog1.Filter = ("RichText*.rtf; )|*.rtf; |TextDocs *.txt;|*.txt");
saveFileDialog1.FilterIndex = 2;
//this gives the title of the savefiledialog.
saveFileDialog1.Title = "save file";
//this prompts the user if they want to overwrite an existing file.
saveFileDialog1.OverwritePrompt = true;
//gets the input made by the savefiledialog.
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//saves the file.
richTextBox1.SaveFile(saveFileDialog1.FileName,
//saves the text in the richbox
RichTextBoxStreamType.RichText);
,我希望能够保存为 rtf 或 txt 格式。谢谢。
I have a quick question, how do you save a file in a different format like in "save as"
so far i got this
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
//this saves the file as a text or richtext.
saveFileDialog1.Filter = ("RichText*.rtf; )|*.rtf; |TextDocs *.txt;|*.txt");
saveFileDialog1.FilterIndex = 2;
//this gives the title of the savefiledialog.
saveFileDialog1.Title = "save file";
//this prompts the user if they want to overwrite an existing file.
saveFileDialog1.OverwritePrompt = true;
//gets the input made by the savefiledialog.
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//saves the file.
richTextBox1.SaveFile(saveFileDialog1.FileName,
//saves the text in the richbox
RichTextBoxStreamType.RichText);
I want to be able to save as ether a rtf or a txt format. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用不同的文件名名称并将其与从原始文件读取的内容缓冲区一起传递给 SaveFile。
Use filename different name and pass it to SaveFile with the read content buffer from origianl file.