Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:42:32+00:00 2026-06-01T11:42:32+00:00

What i want to do is to change two values from the Preferences File

  • 0

What i want to do is to change two values from the Preferences File of Google Chrome Browser. The code i am using now is the below

[DataContract]
public class Mdata
{
    [DataMember(Name = "homepage")]
    public String homepage { get; private set; }
    [DataMember(Name = "homepage_is_newtabpage")]
    public Boolean isNewTab { get; private set; }
    [DataMember(Name = "keep_everything_synced")]
    public Boolean isSynced { get; private set; }
    public Mdata() { }
    public Mdata(String data)
    {
        homepage = data;
    }
}

public static Mdata FindData(String json)
{
    Mdata deserializedData = new Mdata();
    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
    DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedData.GetType());
    deserializedData = ser.ReadObject(ms) as Mdata;
    ms.Close();
    return deserializedData;
}

private void button1_Click(object sender, EventArgs e)
{
    const int LikeWin7 = 6;
    OperatingSystem osInfo = Environment.OSVersion;
    DirectoryInfo strDirectory;
    String path = null, file = null, data;

    if (osInfo.Platform.Equals(System.PlatformID.Win32NT))
        if (osInfo.Version.Major == LikeWin7)
            path = Environment.GetEnvironmentVariable("LocalAppData") +
                @"\Google\Chrome\User Data\Default";
    if (path == null || path.Length == 0)
        throw new ArgumentNullException("Fail. Bad OS.");
    if (!(strDirectory = new DirectoryInfo(path)).Exists)
        throw new DirectoryNotFoundException("Fail. The directory was not fund");
    if (!new FileInfo(file = Directory.GetFiles(strDirectory.FullName, "Preferences*")[0]).Exists)
        throw new FileNotFoundException("Fail. The file was not found.", file);

    Mdata info = FindData(data = System.IO.File.ReadAllText(file));
    Console.WriteLine(info.homepage); // show me http://www.google.com
    Console.WriteLine(info.isNewTab); // prints false
    MessageBox.Show(info.isSynced); // prints true
    }

What i want to do now is to change the values of info.homepage, info.isNewTab and info.isSynced to other values, to be something like (in the preferences file) :

"homepage": "http://www.myWebsite.com/",
"homepage_is_newtabpage": true,
...
"keep_everything_synced": false,

I tried to directrly set new values like this :

 info.homepage = "www.mysite.com";
 info.isNewTab = true;
 info.isSynced = false;

But with no chances!

How can i assign new values to the three objects above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:42:33+00:00Added an answer on June 1, 2026 at 11:42 am

    The code you posted has two problems:

    1. You never write the data back to disk.
    2. You have only mapped the three properties you are interested in. This means only those will get deserialized. And when you change them and write it back to disk only those properties will be serialized as all the other data hasn’t made it into your data structure.

    There are several possible solutions to your problem:

    1. Completely map out the preferences file in your Mdata structure. This is apparently a bit painful as the preferences file is quite large.
    2. The accepted answer to this question shows how to de/serialize an arbitrary JSON object into a dictionary.
    3. Do not use JSON deserialization at all. Just open the file read it line by line and use regular expressions to match the settings you want. Replace the value when you find one. And write each line back (modified or unmodified).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find the precent change in two values from a mysql database.
I want to update two different values with one ajax-response. <span id=nr1>Change this</span> <span
My layout having two parts. I want to change the upper part by keeping
I want change following javascript code to jquery code, How is it? With done
Hello I have two text inputs which get their values from a datepicker. What
I want to change the values of column this in table_one where this =
I want to update the table value comparing with two column values. Query UPDATE
I have two values in an array that I want to have show up
I am using the boost::random to generate random velocity values and I want to
How do I add the values from many variables? If I just had two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.