Convert VB code to C#

Trying to convert VB code to C#. Never really worked with C#. It's just taking a pulling the information from a JSON file so I can upload to a database. Have in VB but want to switch to C#. Below is the VB code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim filePath As String =
            IO.Path.Combine(_desktop, "Upload.txt")

        Dim data As Upload =
            JsonConvert.DeserializeObject(Of Upload)(IO.File.ReadAllText(filePath))
End Sub
Public Class Upload
        Public Property Primaryimage() As WebImage
        Public Property Secondaryimages() As List(Of WebImage)
        Public Property Notes() As List(Of String)
        Public Property SafetyPrecautions() As SafetyPrecautions
End Class
Class WebImage
        Public Property Alt() As String
        Public Property Src() As String
End Class
Public Class SafetyPrecautions
        Public Property Warnings() As List(Of String)
End Class

Open in new window


Might be all wrong but this is what I have for C#

public partial class frmProcessJsonFile : Form
    {
        private string _desktop;
        public frmProcessJsonFile()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string filePath = System.IO.Path.Combine(_desktop, "Upload.txt");

            Upload data = JsonConvert.DeserializeObject<Upload>(System.IO.File.ReadAllText(filePath));
                  }

        public class Upload
            {
             public IEnumerable<WebImage> Primaryimage { get; set; }
              
    }

        class WebImage
        {
            public string Alt { get; set; }
            public string Src { get; set; }
        }
    }

Open in new window


Any help would be appreciated.
MadIceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
There are online converters that will do this for you:



e.g.
class SurroundingClass
{
    private void Form1_Load(object sender, EventArgs e)
    {
        string filePath = System.IO.Path.Combine(_desktop, "Upload.txt");

        Upload data = JsonConvert.DeserializeObject<Upload>(System.IO.File.ReadAllText(filePath));
    }

    public class Upload
    {
        public WebImage Primaryimage { get; set; }
        public List<WebImage> Secondaryimages { get; set; }
        public List<string> Notes { get; set; }
        public SafetyPrecautions SafetyPrecautions { get; set; }
    }

    class WebImage
    {
        public string Alt { get; set; }
        public string Src { get; set; }
    }

    public class SafetyPrecautions
    {
        public List<string> Warnings { get; set; }
    }
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_saigeDeveloperCommented:
Pretty close:

Form1.cs -
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace EE_Q29143073
{
    public partial class Form1 : Form
    {
        const string _desktop = "somepath should be here";
        public Form1()
        {
            InitializeComponent();
        }

        private void OnLoad(object sender, EventArgs e)
        {
            var filePath = Path.Combine(_desktop, "Upload.txt");
            var data = JsonConvert.DeserializeObject<Upload>(File.ReadAllText(filePath));
        }
    }

    class Upload
    {
        public WebImage PrimaryImage { get; set; }
        public List<WebImage> SecondaryImages { get; set; }
        public List<string> Notes { get; set; }
        public SafetyPrecautions SafetyPrecautions { get; set; }
    }

    class WebImage
    {
        public string Alt { get; set; }
        public string Src { get; set; }
    }

    class SafetyPrecautions
    {
        public List<string> Warnings { get; set; }
    }
}

Open in new window

Form1.Designer.cs -
namespace EE_Q29143073
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.OnLoad);
            this.ResumeLayout(false);

        }

        #endregion
    }
}

Open in new window

-saige-
it_saigeDeveloperCommented:
Or as Kaufmed stated...  ;)

-saige-
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

MadIceAuthor Commented:
Thank you. So then this is why I thought I was off. See attached.Inconsistent accessibility error
MadIceAuthor Commented:
Oh, needed to make class to be public. I think this will work but still reviewing.
MadIceAuthor Commented:
Thanks for the help. It also fixed my overall problem and why I had to switch to C#.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.