0

This is my code :

[StorageAccount("BlobConnectionString")]
    public class copyBlobtoazureStorage
    {
        [FunctionName("copyBlobtoazureStorage")]
        public async Task Run(
            [BlobTrigger("input-file/{name}")] Stream inputBlob,
            [Blob("output-file/{name}", FileAccess.Write)] Stream outputBlob,
            string name, ILogger log, ExecutionContext context)
        {
            if (name.EndsWith(".xml"))
            {
                
                XmlDocument doc = new XmlDocument();
                using (XmlReader reader = XmlReader.Create(inputBlob))
                {
                    doc.Load(reader);

                }

                string jsonText = JsonConvert.SerializeXmlNode(doc);
                byte[] info = new UTF8Encoding(true).GetBytes(jsonText);
                outputBlob.Write(info, 0, info.Length);
            }


            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {inputBlob.Length} Bytes");


        }
    }

I want to change the xml file in the input file to text file in output file. I tried to use {name}.txt but I got note.xml.txt but I just want note.txt ! any suggestion ?

  • Is the only bit that's causing a problem for you the name? If so, you know that the name ends with ".xml", so just use `Substring` to get the name before those four characters... – Jon Skeet Mar 14 '22 at 14:18
  • `name.Replace(".xml",".txt")` – Luuk Mar 14 '22 at 14:21
  • @Luuk: That depends on whether there might be multiple parts, e.g. "xyz.xml.xml" - I'd expect that to become "xyz.xml.txt" rather than "xyz.txt.txt" – Jon Skeet Mar 14 '22 at 14:22
  • @JonSkeet: True, But the question implies not having double extensions. Why else would there be an attempt not to have "note.xml.txt" ? – Luuk Mar 14 '22 at 14:39
  • @Luuk: No, the question implies not *creating* a double extension when the input only had one extension. There's a huge difference those two. – Jon Skeet Mar 14 '22 at 16:20
  • @JonSkeet: Might be a language problem on my side then.... (sorry). – Luuk Mar 14 '22 at 16:28
  • XML is a text file. Maybe all you want to do is change the extension from xml to txt. – jdweng Mar 15 '22 at 09:21

0 Answers0