本帖最后由 gyvgahb2 于 2010-04-14 14:43:47 编辑

解决方案 »

  1.   

    建议你换成 @"C:\Documents and Settings\Administrator\桌面\C#随记.txt" 试试。
      

  2.   

    OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog.Filter = "Excel文件|*.xls;*.txt";
                openFileDialog.RestoreDirectory = true;
                openFileDialog.Title = "打开文件";
                openFileDialog.FilterIndex = 1;            if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    return (openFileDialog.FileName);
                }
                else return String.Empty;我是从这里读出来的路径,怎么改?
      

  3.   

    你用openFileDialog.InitialDirectory读出来的已经是全物理路径了...你传给TemplatePath参数的是什么?把“System.Windows.Forms.Application.StartupPath + "//" +”删除掉...
      

  4.   

    public string ReadFile(string TemplatePath)
            {
                //---------------------读html模板页面到stringbuilder对象里---- 
                StringBuilder htmltext = new StringBuilder();
                try
                {
                    using (StreamReader sr = new StreamReader(TemplatePath, System.Text.Encoding.Default)) //模板页路径
                    {
                        String line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            htmltext.Append(line);
                        }
                        sr.Close();
                    }
                    return htmltext.ToString();
                }
                catch(Exception ex)
                {
                    return "";            }
            }这个怎么处理成,一行一行的读? 不然从TXT本来是排好版的,读到TEXTBOX里就变乱了...
      

  5.   

    TextBox默认不支持换行符...必须设置其Multiline属性为true,同时将WordWrap属性和ScrollBars属性设置为适当的值...或者改用RichTextBox...
      

  6.   

    .其实我就是想直接读取TXT,不赋到TEXTBOX里面,这样再插入数据库就不会受到格式乱的影响了吧?