嗨,代码错误!!! [英] hi, error in code!!!!

查看:69
本文介绍了嗨,代码错误!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("E:\\Testing");
System.IO.FileSystemInfo[] files = di.GetDirectories();
checkedListBox1.Items.AddRange(files);

Options opt = new Options();
XmlDocument document = new XmlDocument();
XmlElement rootElement = document.CreateElement("Items");
foreach (var itemObj in opt.checkedListBox1.CheckedItems)
{
XmlElement newItem = document.CreateElement("Item");
newItem.InnerText =itemObj.ToString();
rootElement.AppendChild(newItem);
}
document.AppendChild(rootElement);
document.Save("test.xml");




代码出错?! 选项opt = new Options();"




error at code?! " Options opt = new Options();"

Options opt = new Options();




错误!未定义

代码错误:
Error 1 The type or namespace name ''Options'' could not be found (are you missing a using directive or an assembly reference?)




error! Is not defined

error at code :
Error 1 The type or namespace name ''Options'' could not be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
 
namespace WindowsFormsApplication18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("E:\\Testing");
            System.IO.FileSystemInfo[] files = di.GetDirectories();
            checkedListBox1.Items.AddRange(files);
 

            Options opt = new Options();
            XmlDocument document = new XmlDocument();
            XmlElement rootElement = document.CreateElement("Items");
            foreach (var itemObj in opt.checkedListBox1.CheckedItems)
            {
                XmlElement newItem = document.CreateElement("Item");
                newItem.InnerText = itemObj.ToString();
                rootElement.AppendChild(newItem);
            }
            document.AppendChild(rootElement);
            document.Save("test.xml");
        }
    }
}

推荐答案

我认为您是从Internet复制代码并尝试对其进行编译.

http://bytes.com/topic/c-sharp/answer/923938-create-xml-file-using-folder-path [
I think you are copied code from internet and try to compile it.

http://bytes.com/topic/c-sharp/answers/923938-create-xml-file-using-folder-path[^]

able to find same code from that link.

that is not a complete solution, it is small part of a windows form project. you can''t copy past and run it.

There will be compile errors since you don''t have defined Options in your project. It may be a windows form in that given link.


这篇关于嗨,代码错误!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆