Inquiridor
Download Arquivo C# ( em pasta )

Pergunta
-
Tudo Bem galera ? espero que sim estou com essa dificuldade na hora que ele vai baixar ele nao baixa a pasta e sim nao coloca a extenssao do arquivo ! como fazer para ele baixar tudo dentro dessa pasta ? ou baixa a mesma ?
estou fazendo assim:
private void button2_Click(object sender, EventArgs e) { string remoteUri = "http://meusite.com/"; string fileName = "oqbaixar", myStringWebResource = null; WebClient myWebClient = new WebClient(); myWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(CompleteDown); myWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); myStringWebResource = remoteUri + fileName; myWebClient.DownloadFile(myStringWebResource,fileName); } private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; } private void CompleteDown(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("Download Completo"); }
desde ja OBG
Todas as Respostas
-
Olá, cara eu tive que zipar tudo e depois fazer o download desse zip, porém fiz isso com a dll Ionic.Zip, Zlib, Bzip2 e o método abaixo.
private void Zipar(string caminhoFisico, string caminhoVirtual) { string erros = string.Empty; bool cript = false; try { var filesToInclude = new System.Collections.Generic.List<String>(); String sMappedPath = Server.MapPath(caminhoVirtual); var arquivos = Directory.GetFiles(caminhoFisico); DirectoryInfo source = new DirectoryInfo(caminhoFisico); FileInfo[] files = source.GetFiles(); foreach (FileInfo file in files) { filesToInclude.Add(Path.Combine(source.FullName, file.Name)); } if (filesToInclude.Count == 0) { erros += "Você não selecionou nenhum arquivo?<br/>\n"; } else { Response.Clear(); Response.BufferOutput = false; System.Web.HttpContext c = System.Web.HttpContext.Current; String ReadmeText = String.Format("Olá!\n\n" + "Este é um arquivo zip que foi gerado dinamicamente a {0}\n" + "por uma página ASP.NET em execução na máquina chamada '{1}'.\n" + "O tipo de servidor é: {2}\n" + "A senha usada: '{3}'\n" + "criptografia: {4}\n", System.DateTime.Now.ToString("G"), System.Environment.MachineName, c.Request.ServerVariables["SERVER_SOFTWARE"], UtilController.PegarUsuarioLogado.Nome, (cript) ? EncryptionAlgorithm.WinZipAes256.ToString() : "None" ); string archiveName = String.Format("PlanilhasDaSemana-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss")); Response.ContentType = "application/zip"; Response.AddHeader("content-disposition", "inline; filename=\"" + archiveName + "\""); using (ZipFile zip = new ZipFile()) { // the Readme.txt file will not be password-protected. zip.AddEntry("leaime.txt", ReadmeText, Encoding.Default); if (!String.IsNullOrEmpty(UtilController.PegarUsuarioLogado.Nome)) { zip.Password = UtilController.PegarUsuarioLogado.Nome; if (cript) zip.Encryption = EncryptionAlgorithm.WinZipAes256; } // filesToInclude is a string[] or List<String> zip.AddFiles(filesToInclude, "Planilhas_Semanais"); zip.Save(Response.OutputStream); } Response.Close(); } } catch (Exception) { Console.Write(erros); } }
Funciona muito bem!