I want to store a .NET object into Azure Blob Storage.
Currently I serialize it into an XML file using TextWriter
(episodeList
is the object I want serialized):
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
XmlAttributes Xmlattr = new XmlAttributes();
Xmlattr.XmlRoot = new XmlRootAttribute("EPISODES");
overrides.Add(typeof(List<EpisodeData>), Xmlattr);
XmlSerializer serializer = new XmlSerializer(typeof(List<EpisodeData>), overrides);
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, episodeList);
textWriter.Close();
and then upload the file into Blob Storage:
CloudBlobClient blobStorage = createOrGetReferenceOfBlobStorage(folderName);
string uniqueBlobName = string.Format("{0}/{1}", folderName, fileName);
CloudBlockBlob blob = clouBblockBlobPropertySetting(blobStorage, uniqueBlobName, ".txt");
using (StreamWriter writer = new StreamWriter(blob.OpenWrite()))
{
writer.Write(content);
}
Is it possible to somehow skip the temporary file so that the XML is directly uploaded into Azure Blob Storage?
Create Power Automate Desktop FlowGo to containers and create a new container. Open the container and on the and navigate to Shared access signature. Select add, create, and write permission, change the time if needed, and press Generate SAS token and URL. Copy the Blob SAS URL and save it as the variable in the flow.
Azure Blob is an object storage solution. It allows you to store a large amount of unstructured data, whereas Azure files permit you to develop managed file share for the cloud. Moreover, Azure file share can also be mounted by the on premises deployment of Windows, Linux, and macOS.
You could do the following. Create a MemoryStream
instance and use XmlSerializer.Serialize(Stream stream)
to serialize the object into the memory stream, then "rewind" the stream to beginning using Seek()
. Then you call CloudBlob.UploadFromStream()
to upload the stream contents to the blob.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With