richTextBox1.LoadFile("d:\\source.rtf", RichTextBoxStreamType.RichText);提示文件格式无效
2010-11-17 21:20
387 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ComboBoxExam
{
public partial class FormComboBox : Form
{
private void EditEnable(object sender, EventArgs e)
{
//由于comBoxName可以由用户输入新姓名,判断时不能使用SelectedIndex属性
if (comboBoxName.Text != "" && comboBoxDepartment.SelectedIndex > -1)
{
richTextBox1.Enabled = true;
buttonOpenFile.Enabled = true;
buttonSaveFile.Enabled = true;
}
}
public FormComboBox()
{
InitializeComponent();
}
private void buttonAddName_Click(object sender, EventArgs e)
{
if (comboBoxName.Text != "")
{
bool newitem = true;
//判断当前comboBoxName中用户输入的姓名是否已经存在于下拉列表中
for (int i = 0; i < comboBoxName.Items.Count; i++)
{
string oneitem = Convert.ToString(comboBoxName.Items[i]);
if (oneitem == comboBoxName.Text)
{
newitem = false;
}
}
//如果用户输入的姓名不在下拉列表中,则添加
if (newitem)
{
comboBoxName.Items.Add(comboBoxName.Text);
}
}
}
private void buttonOpenFile_Click(object sender, EventArgs e)
{
richTextBox1.LoadFile("d:\\source.rtf", RichTextBoxStreamType.RichText);
}
private void buttonSaveFile_Click(object sender, EventArgs e)
{
//保存文件,并清除richTextBox1中的文本,给出提示信息
richTextBox1.SaveFile("d:\\result.rtf",RichTextBoxStreamType.RichText);
richTextBox1.Clear();
MessageBox.Show(" 文件保存完毕!");
richTextBox1.Enabled = false;
buttonOpenFile.Enabled = false;
buttonSaveFile.Enabled = false;
}
}
}
由于是直接在d盘新建一个source.doc,或者是source.txt,然后改后缀为.rtf,运行程序会提示文件格式不对,新建文件另存为source.rtf,运行正常,不存在上述文件格式无效的提示,发这个东西的目的在于让和自己一样的初学者少走弯路。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ComboBoxExam
{
public partial class FormComboBox : Form
{
private void EditEnable(object sender, EventArgs e)
{
//由于comBoxName可以由用户输入新姓名,判断时不能使用SelectedIndex属性
if (comboBoxName.Text != "" && comboBoxDepartment.SelectedIndex > -1)
{
richTextBox1.Enabled = true;
buttonOpenFile.Enabled = true;
buttonSaveFile.Enabled = true;
}
}
public FormComboBox()
{
InitializeComponent();
}
private void buttonAddName_Click(object sender, EventArgs e)
{
if (comboBoxName.Text != "")
{
bool newitem = true;
//判断当前comboBoxName中用户输入的姓名是否已经存在于下拉列表中
for (int i = 0; i < comboBoxName.Items.Count; i++)
{
string oneitem = Convert.ToString(comboBoxName.Items[i]);
if (oneitem == comboBoxName.Text)
{
newitem = false;
}
}
//如果用户输入的姓名不在下拉列表中,则添加
if (newitem)
{
comboBoxName.Items.Add(comboBoxName.Text);
}
}
}
private void buttonOpenFile_Click(object sender, EventArgs e)
{
richTextBox1.LoadFile("d:\\source.rtf", RichTextBoxStreamType.RichText);
}
private void buttonSaveFile_Click(object sender, EventArgs e)
{
//保存文件,并清除richTextBox1中的文本,给出提示信息
richTextBox1.SaveFile("d:\\result.rtf",RichTextBoxStreamType.RichText);
richTextBox1.Clear();
MessageBox.Show(" 文件保存完毕!");
richTextBox1.Enabled = false;
buttonOpenFile.Enabled = false;
buttonSaveFile.Enabled = false;
}
}
}
由于是直接在d盘新建一个source.doc,或者是source.txt,然后改后缀为.rtf,运行程序会提示文件格式不对,新建文件另存为source.rtf,运行正常,不存在上述文件格式无效的提示,发这个东西的目的在于让和自己一样的初学者少走弯路。
相关文章推荐
- android 上传文件"Content-Type",为"application/octet-stream" 用php程序在服务端用$GLOBALS['HTTP_RAW_POST_DATA']接受(二)
- struts2实现文件导出type="stream"
- Android Eclipse导入源码时对自己新增的class文件提示"XXX cannot be resolved to a type"的解决办法
- Hibernate配置文件错误提示,The content of element type "list" must match "(meta*,subselect?,cache?,synchroniz
- spring mvc源码-》MultipartReques类-》主要是对文件上传进行的处理,在上传文件时,编码格式为enctype="multipart/form-data"格式,以二进制形式提交数据,提交方式为post方式。
- 打包后的Jar文件真机安装时提示"jar文件无效"的解决方案
- 右键新建excel文档无法打开,提示“文件格式或扩展名无效”
- struts2文件下载 <result type="stream">
- 打开Excel时提示"您尝试打开的文件**.xls的格式与文件扩展名指定的格式不一致"
- C# Visual Studio 2005中RichTextBox保存文件为rtf格式
- 通过GetManifestResourceStream加载文件出现错误提示“null值”对于“stream”无效
- struts2文件下载 <result type="stream">
- action type="stream" 文件下载
- "格式太旧或是类型库无效。 (异常来自 HRESULT:0x80028019 (TYPE_E_UNSUPFORMAT))"
- Excel2016右键新建工作表,打开时提示“因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。”的解决办法
- C# Visual Studio 2005中RichTextBox打开文件为rtf格式
- struts2框架校验文件配置提示The content of element type "validators" must match "(validator)+".
- vbs 写文件提示"无效的过程调用或参数"
- struts2文件下载 <result type="stream">
- C# 读取app.config配置文件 节点键值,提示 "System.TypeInitializationException 类型初始值设定项引发异常" 错误的解决方案