3

I want to read Excel file from JSON data which I am sending from ARC, Can anyone help me to sorted out?

public bool ControlAttachment(AttachmentFile file)
{
    try
    {
        if (file != null && file.File != null)
        {
            string xlsfile = file.File;
            string [] xls = {"application/excel","application/vnd.msexcel","xls","xlsx","application/vnd.ms-excel",};

            if (xls.ToList().Contains(file.FileType.Trim()))
            {
                file.FileType = ".xls";
                byte[] contents = Convert.FromBase64String(xlsfile);
                string LogFilePaths = ConfigurationManager.AppSettings["ExcelMapperPath"];
                string fileName = file.FileName.Split('.')[0] + file.FileType;
                string LogFile = HttpContext.Current.Server.MapPath(LogFilePaths + file.FileName.Split('.')[0] + file.FileType);

                System.IO.File.WriteAllBytes(LogFile, contents);

                if (!File.Exists(LogFile))
                { 
                    File.Create(LogFile).Dispose();
                }
                MemoryStream ms = new MemoryStream();
                using (var fs = new FileStream(LogFile, FileMode.Open, FileAccess.Write))
                { 
                        ms.CopyTo(fs);
                        ms.Dispose();
                }
            }
        }
        return true;
    }
    catch 
    {
        return false;
    }
}
Stafford Williams
  • 9,696
  • 8
  • 50
  • 101
Purvi
  • 31
  • 1
  • 2
  • Possible duplicate of [.NET Excel Library that can read/write .xls files](http://stackoverflow.com/questions/5852678/net-excel-library-that-can-read-write-xls-files) – Stafford Williams May 27 '16 at 05:48

0 Answers0