Exemplo n.º 1
0
    private void SaveFile(string fileToSave, string extension)
    {
        DialogResult result = saveFileDialog1.ShowDialog();

        if (result.ToString() == "OK")
        {
            Application.DoEvents();
            string e = Path.GetExtension(saveFileDialog1.FileName);

            if (e != null)
            {
                if (e.ToLower() == ".html" || e.ToLower() == ".xml")
                {
                    File.Copy(fileToSave, saveFileDialog1.FileName, true);
                }
                else if (e.ToLower() == ".zip")
                {
                    string tempFileName        = string.Format("{0}.{1}", Path.GetFileNameWithoutExtension(saveFileDialog1.FileName), extension);
                    string tempFileNameAndPath = string.Format(@"{0}\{1}", GenericHelper.TempPath, tempFileName);
                    File.Copy(fileToSave, tempFileNameAndPath, true);
                    Compression.CompressFile(tempFileNameAndPath, saveFileDialog1.FileName);
                    File.Delete(tempFileNameAndPath);
                }
                else
                {
                    MessageBox.Show("Please enter a valid file extension.", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
    }
Exemplo n.º 2
0
 public async Task <IActionResult> OnPostUploadAsync([FromForm] IFormFile file, [FromRoute] string name)
 {
     try
     {
         Compression.DirectoryCreation();
         var filePath = Path.GetFullPath(Directory.GetCurrentDirectory() + "\\Temp\\" + file.FileName);
         if (file != null)
         {
             using (var stream = new FileStream(filePath, FileMode.Create))
             {
                 await file.CopyToAsync(stream);
             }
         }
         else
         {
             return(StatusCode(500));
         }
         string     FinalFile = Compression.CompressFile(filePath, file.FileName, name);
         FileStream Sender    = new FileStream(FinalFile, FileMode.OpenOrCreate);
         return(File(Sender, "text/plain", name + ".lzw"));
     }
     catch
     {
         return(StatusCode(500));
     }
 }