Ilano 0 Denunciar post Postado Fevereiro 13, 2007 Olá pessoal,Em minha aplicação web, como posso fazer, em VB, com q um usuário faça o Upload de um arquivo para a minha pasta de imagens, por exemplo?Estou usando o componente FileUpload.Grato,Ilano Compartilhar este post Link para o post Compartilhar em outros sites
Ilano 0 Denunciar post Postado Fevereiro 13, 2007 Olá pessoal,Acredito q estou próximo. Estou tentando fazer assim: Private Sub EnviarArquivo() Dim savePath As String = "~/Imagens/" If (FileUpload1.HasFile) Then Dim fileName As String = FileUpload1.FileName savePath += fileName FileUpload1.SaveAs(savePath) UploadStatusLabel.Text = "Your file was saved as " & fileName Else UploadStatusLabel.Text = "You did not specify a file to upload." End If End SubSó q está dando o seguinte erro:The SaveAs method is configured to require a rooted path, and the path '~/Imagens/Logo_Centec.gif' is not rooted.Alguém pode me ajudar? Compartilhar este post Link para o post Compartilhar em outros sites
Macal 0 Denunciar post Postado Fevereiro 16, 2007 Bom, eu programo em C#, mas existem sites que traduzem de C# para VB. Estou usando esse codigo e esta funcionando: protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { Boolean fileOK = false; //Adicione aqui os diretorios para cada componente FileUpload. Aqui temos "path" e "path2" String path = Server.MapPath("~/diretorio/"); String path2 = Server.MapPath("~/diretorio2/"); if (FileUpload1.HasFile) { String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); String[] allowedExtensions = { ".doc", ".txt" }; //Adicione as extensões que desejar for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (FileUpload2.HasFile) { String fileExtension = System.IO.Path.GetExtension(FileUpload2.FileName).ToLower(); String[] allowedExtensions = { ".doc", ".txt" }; //Adicione as extensões que desejar for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { // Para cada componente FileUpload, crie uma seção dessas try { FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName); Label1.Text = "Upload completo!"; } catch (Exception ex) { Label1.Text = "Upload falhou."; } //------------------------------------------------------- try { FileUpload2.PostedFile.SaveAs(path2 + FileUpload2.FileName); Label1.Text = "Upload completo!"; } catch (Exception ex) { Label1.Text = "Upload falhou."; } } else { Label1.Text = "Tipo de arquivo incorreto."; } } } Compartilhar este post Link para o post Compartilhar em outros sites