Home > Mobile >  How to retrieve the value from Headers in C#?
How to retrieve the value from Headers in C#?

Time:11-28

I have a variable fileContent which holds the value of FileName. I want the filename value to be stored in separate variable. How can I do this using C#?

enter image description here

Please find below code: This is what I have tried :

var fileContent = provider.Contents.FirstOrDefault(c => c.Headers.ContentDisposition.Name.Replace("\"", "") == "file");

var fileName = fileContent.Headers.ContentDisposition.FileName.FirstOrDefault();

I am getting the integer value as 34 in the variable fileName - instead of "Test.txt".. Please help to fix this!

CodePudding user response:

don't treat Filename as an array and leave out the .FirstOrDefault(). The 34 is probably the ascii value of the opening quote in the file name.

Personally I never use var. Replace with the actual type you need, and you will see a better error message.

To remove the quotes, you might try to call something like Trim('"'). I don't have C# here to test though :-(

  • Related