开发者

strore a xml file in registry and after restore it

I want strore a xml file in registry and after restore it.Do it possible?

i try create with this code But it Not Responding?!what is problem?

enter code here

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        MemoryStream stream = new MemoryStream();
        BinaryFormatter formatter = new BinaryFormatter();
        List<int> f = new List<int>();
        f.Add(4);

        formatter.Serialize(stream, f);
        byte[] binary =开发者_运维技巧 stream.ToArray();
        string yu = Encoding.UTF8.GetString(binary);


        RegistryKey key = Registry.Users;
        RegistryKey key2 = key.OpenSubKey(".DEFAULT", true);
        key2.SetValue("my4",yu,RegistryValueKind.String );     // "why writed empty string in registry
    }
}


A few remarks on this:

1: The registry isn't the right place to save a whole XML file. More normal might be to save the xml to the filesystem and possibly save its location in the registry.

2: Registry.Users refers to a location in the registry where you wouldn't normally save data. Either it should be in HKey_Current_User (Registry.CurrentUser) or HKey_Local_Machine (Registry.LocalMachine) depending on whether the data is specific to all users on the PC or just the current user.

3: I'm extremely confused about what the coding in the first two questions is trying to achieve. Its a long way around to make a string, the contents may not be compatible with the registry and I can see anything related to XML.

I would make a strong warning that updating the registry without knowing exactly what you're doing is very dangerous. It could easily lead to odd errors or even a non-booting PC. Only proceed with trying registry updates once you fully understand how it works. I would start with an article like this one and read on from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜