Fórum Realizando Upload e download de arquivos #604848
25/08/2019
0
Olá bom dia a todos. Eu realizei o tutorial da Devmedia "ASP.NET MVC 4: Realizando Upload e download de arquivos" porém gostaria de acrescentar a implementação para deletar os arquivos que realizei o Upload e também ordenar de forma decrescente. Se possível gostaria que alguém pudesse me ajudar pois sou iniciante em aspnet. Desde já agradeço

Grasielly Silva
Curtir tópico
+ 0
Responder
Posts
11/09/2019
Stella Oliveira
Olá bom dia a todos. Eu realizei o tutorial da Devmedia "ASP.NET MVC 4: Realizando Upload e download de arquivos" porém gostaria de acrescentar a implementação para deletar os arquivos que realizei o Upload e também ordenar de forma decrescente. Se possível gostaria que alguém pudesse me ajudar pois sou iniciante em aspnet. Desde já agradeço
Para ordenar o arquivo eu faria da seguinte forma:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | try { var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); foreach (var file in provider.Contents) { var buffer = await file.ReadAsStreamAsync(); List< string []> arquivoGlobal = new List< string []>(); using (var reader = new StreamReader(buffer, Encoding.Default, true )) { string conteudo; while ((conteudo = reader.ReadLine()) != null ) { string [] linhas = conteudo.Split( '' ; '' ); arquivoGlobal.Add(linhas); } } var qtdColunas = arquivoGlobal.First().Count(); arquivoGlobal.RemoveAt(0); arquivoGlobal = arquivoGlobal.OrderBy(x => x[0]).ThenBy(x => x[2]).ToList(); } } catch (Exception ex) { string erro = ex.Message; } |
E para deletar:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // Specify the directories you want to manipulate. string path = @"c:\\\\MyDir" ; string target = @"c:\\\\TestDir" ; try { // Determine whether the directory exists. if (!Directory.Exists(path)) { // Create the directory it does not exist. Directory.CreateDirectory(path); } if (Directory.Exists(target)) { // Delete the target to ensure it is not there. Directory.Delete(target, true ); } // Move the directory. Directory.Move(path, target); // Create a file in the directory. File.CreateText(target + @"\\\\myfile.txt" ); // Count the files in the target directory. Console.WriteLine( "The number of files in is " , target, Directory.GetFiles(target).Length); } catch (Exception e) { Console.WriteLine( "The process failed: " , e.ToString()); } |
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)