.NET Framework Developer Center > .NET Development Forums > .NET Base Class Library > How to get original file name from a byte array (contains file from Mac or Windows)
Ask a questionAsk a question
 

AnswerHow to get original file name from a byte array (contains file from Mac or Windows)

  • Monday, November 02, 2009 8:32 PMd_vm23 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a web method that receives a byte array of a file that is uploaded.  It can be a Windows file or a Mac file.
    I would like to find out what the original file name is somehow.  I thought this would be possible maybe either by:
    1) Getting the original filename from inside the byte array (Byte []) or
    2) Writing the file as is to the local physical disk and then reading the file name via Path.GetFileName().  However the method File.WriteAllBytes requires a FileName !  I would like to use the default file name and just set the Path.

    I am stumped on this one.

Answers

  • Tuesday, November 03, 2009 5:42 PMTergiver Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    It is not possible. The information is not there to be discovered. Whatever method asked the user to enter a local file path has to pass the filename in addition to the file content.

All Replies

  • Tuesday, November 03, 2009 5:42 PMTergiver Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    It is not possible. The information is not there to be discovered. Whatever method asked the user to enter a local file path has to pass the filename in addition to the file content.