Convert xml to json with C#

While converting XML to JSON using c#, By providing the data within the class,I’m getting the output.I need to fetch data from file present in folder .Could anyone please help on this

using Newtonsoft.Json;
using System;
using System.Windows.Forms;
using System.Xml;

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

    private void Form1_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(" <Student>\r\n    <Student_Name>Preethi</Student_Name>\r\n    <SSN>45679</SSN>\r\n    <Course>Electronics and communication</Course>\r\n    <Address>\r\n      <Line_1>#1, 6th cross</Line_1>\r\n      <Line_2>Victoria Layout</Line_2>\r\n      <City>Bangalore</City>\r\n      <Country>India</Country>\r\n    </Address>\r\n  </Student>\r\n</Root>");
        string jsonText = JsonConvert.SerializeXmlNode(doc);
        //Console.WriteLine(jsonText);
        MessageBox.Show(jsonText);
    }
}

}

I don’t see a question or a description of what is stopping you, hard to tell what you want.

how to give the local directory path to fetch xml file

Are you asking about the current working directory of your process or about how to open some kind of dialogue for a user to select a directory? Or something else entirely perhaps?

I want to list the files present in azure blob.
Store this list of files into a array.
My xml to json converter should be able fetch the xml file one after the other and convert it into json.
This json output must be saved back to azure blob.
How can i do this?

Old question but would like to answer.

Get files and Directory list from Azure blog using C# code as below

CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(blobConectionString);

var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
var backupContainer = backupBlobClient.GetContainerReference(container);

// useFlatBlobListing is true to ensure loading all files in
// virtual blob sub-folders as a plain list
var list = backupContainer.ListBlobs(useFlatBlobListing: true);
var listOfFileNames = new List<string>();

foreach (var blob in blobs) {
  var blobFileName = blob.Uri.Segments.Last();
  listOfFileNames.Add(blobFileName); 
}

return listOfFileNames;

Now, once you have all the files filter .json files using Extension and use below code

   XmlDocument doc = new XmlDocument();
        doc.LoadXml(" <Student>\r\n    <Student_Name>Preethi</Student_Name>\r\n    <SSN>45679</SSN>\r\n    <Course>Electronics and communication</Course>\r\n    <Address>\r\n      <Line_1>#1, 6th cross</Line_1>\r\n      <Line_2>Victoria Layout</Line_2>\r\n      <City>Bangalore</City>\r\n      <Country>India</Country>\r\n    </Address>\r\n  </Student>\r\n</Root>");
        string jsonText = JsonConvert.SerializeXmlNode(doc);

Or you can also take a look here Converting JSON to XML and XML to JSON in C#

Once you have got converted JSON save it back to Azure blob as a file using below sample Code

// Retrieve storage account from connection string.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageKey");

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

Hopefully it will help, thanks