예제 #1
0
        public async Task <IActionResult> AddNonEncryptedFile(IFormFile uploadedFile, string key)
        {
            if (uploadedFile != null)
            {
                // путь к папке Files
                string path = Directory.GetCurrentDirectory() + "_" + uploadedFile.FileName;

                NonEncryptedText.CurrentFilePath      = path;
                NonEncryptedText.CurrentFileDirectory = Directory.GetCurrentDirectory();

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    uploadedFile.CopyToAsync(fileStream);
                }

                FileModel file = new FileModel {
                    Name = uploadedFile.FileName, Path = path
                };

                string FileExtension = Path.GetExtension(file.Name);

                if (FileExtension == ".txt")
                {
                    using (TextReader tr = new StreamReader(path))
                    {
                        NonEncryptedText.Text = TxtReader.Read(path);
                    }
                    //EncryptedText.Text = TxtReader.Read(path);
                }
                else if (FileExtension == ".docx" || FileExtension == ".doc")
                {
                    using (TextReader tr = new StreamReader(path))
                    {
                        NonEncryptedText.Text = DocxReader.Read(path);
                    }
                }
                else
                {
                    Response.WriteAsync("<script>alert('This is wrong file format!!! Go to the previous page!!!');</script>");
                    return(View("Encode"));
                }
            }
            else
            {
                Response.WriteAsync("<script>alert('There is nothing in file input!!! Go to the previous page!!!');</script>");
                return(View("Encode"));
            }

            if (key != null || Key.CheckIfAlphabet(key))
            {
                Key.Text = key.ToUpper();
            }
            else
            {
                Response.WriteAsync("<script>alert('There is a wrong key!!! Go to the previous page!!!');</script>");
                return(View("Encode"));
            }

            return(View("EncodeDownload"));
        }