0

I am getting imported file to Web API.

1) How do I identify File Type csv or excel or pdf file.

2) I want to save file On specific folder with User provided File name how can I achieve that.

 [HttpPost]
    public async Task<IHttpActionResult> UploadData()
    {

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

              foreach (MultipartFileData file in provider.FileData)
                {
                    File.Move(file.LocalFileName, filePath);
                    break;
                }
                File.Delete(provider.FileData[1].LocalFileName);
   }
BorHunter
  • 893
  • 3
  • 18
  • 44
ineffable p
  • 1,207
  • 2
  • 22
  • 46
  • Those links may be useful: http://stackoverflow.com/questions/4177922/how-to-determine-file-type, http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx. – Lukasz M Feb 06 '14 at 22:20
  • For file type detection you can use my little library https://filetypedetective.codeplex.com/ number of types is limited, but it will tell you if this is excel or pdf. CSV is just a text file with `.csv` extension. – trailmax Feb 07 '14 at 00:26

0 Answers0