0
votes

I've a file containing which I upload to Azure blobstorage, the file looks like this:

TAR-2312;12;;123;1A1195061;231
SSS 2637218;2/9;              
1A1321268;1231195061

My trigger processes the file, but I get The filename, directory name, or volume label syntax is incorrect: "path.../TAR-2312;12;;123;1A1195061;231 SSS 2637218;2/9;1A1321268;1231195061

It happens in the highlighted call

public static XDocument Convert(Stream blob)
{

   StreamReader reader = new StreamReader(blob);
   var contentOfFile = reader.ReadToEnd();

   ***List<string> lines = File.ReadLines(contentOfFile).Take(2).ToList();***

Any ideas why this is and how to fix it?

2

2 Answers

1
votes

The reason you're getting this error is because File.ReadLines method expects path to a file and you're passing file contents.

In your scenario, it would be better to split the contents of the file using new line character delimiter (either \n or \r\n) using String.Split method.

1
votes

List lines = File.ReadLines(contentOfFile).Take(2).ToList();

File.ReadLines(string path) requires path and not the content. More details here: ReadLines

Whatever you are trying to achieve can be done as below:

//Get the reference of container and pass the blob name
CloudBlob blob = container.GetBlobReference("BlobFileName.txt");
List<string> lines = new List<string>();
int countTake = 2;
using (var stream = blob.OpenRead())
{
    using (StreamReader reader = new StreamReader(stream))
    {
        int count=0;
        while (!reader.EndOfStream && count!=countTake)
        {
            count++;
            lines.Add(reader.ReadLine());
        }
    }
}