You can serialize your response and save it as a text file.
It can be accessed at anytime or place in your application.
Here is a simple demo that just collects the html from the front page of Bing.
The html source is now serialized and saved to file that can be accessed anywhere by the sample app.
Ensure your program can read and write to the file without elevated permissions when deploying (AppData folder etc). Local testing is fine. Here is code you can drop into a new Console app for testing purposes.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace SerializeObject
{
class Program
{
static void Main(string[] args)
{
//ensure you delete StorageFile.txt if you encounter errors or change structure of MyObject
GetInternetString("http://www.bing.com");
}
private static void GetInternetString(string url)
{
using (var wb = new WebClient())
{
var response = wb.DownloadString(url);
Serialize(response);
}
}
private static void Serialize(string webPageContent)
{
try
{
MyObject saveThis = new MyObject(webPageContent);
IFormatter formatter = new BinaryFormatter();
using (Stream stream = new FileStream("StorageFile.txt", FileMode.Append, FileAccess.Write))
{
formatter.Serialize(stream, saveThis);
stream.Close();
}
Deserialize();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r" + ex.StackTrace);
}
}
private static void Deserialize()
{
try
{
//change this to your specific use
var lstSessionProjectFilesTrimsSaveThis = new List<MyObject>();
using (var fileStream = new FileStream("StorageFile.txt", FileMode.Open))
{
var bFormatter = new BinaryFormatter();
while (fileStream.Position != fileStream.Length)
{
//change this to your specific use
lstSessionProjectFilesTrimsSaveThis.Add((MyObject)bFormatter.Deserialize(fileStream));
}
}
foreach (var VARIABLE in lstSessionProjectFilesTrimsSaveThis)
{
Console.WriteLine(VARIABLE.WebPageContent);
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}
[Serializable] //mandatory to have this declaration
public class MyObject
{
public MyObject(string webPageContent)
{
WebPageContent = webPageContent;
}
public string WebPageContent { get; set; }
}
}
}