Hi @Raki ,
First, you need to read the json string using the File.ReadAllText method.
string allText = System.IO.File.ReadAllText(Server.MapPath("~/Files/Test.txt"));
Then use the JObject.Parse method: load a JObject from a string containing JSON.
The JObject.Parse method needs to add a reference: using Newtonsoft.Json.Linq;
JObject jObject = JObject.Parse(allText);
var value = jObject["cd6bfb7fe59f48d78ef3cc8012d85abe"]["data"]["Insured Information"]["Company Name"]["value"].ToString();
string title = jObject.SelectToken("$.cd6bfb7fe59f48d78ef3cc8012d85abe..title").ToString();
You can refer to the following demo:
<asp:Button Text="Download File" runat="server" OnClick="DownloadFile" />
protected void DownloadFile(object sender, EventArgs e)
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/Files/Test.txt"));
JObject jObject = JObject.Parse(allText);
var value = jObject["cd6bfb7fe59f48d78ef3cc8012d85abe"]["data"]["Insured Information"]["Company Name"]["value"].ToString();
string title = jObject.SelectToken("$.cd6bfb7fe59f48d78ef3cc8012d85abe..title").ToString();
//File to be downloaded.
string fileName = "Test.pdf";
if (value == "Lenox Gardens Apt Corp")
{
//Set the New File name.
string newFileName = title;
//Path of the File to be downloaded.
string filePath = Server.MapPath(string.Format("~/Files/{0}", fileName));
//Setting the Content Type, Header and the new File name.
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + newFileName);
//Writing the File to Response Stream.
Response.WriteFile(filePath);
Response.Flush();
Response.End();
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.