1
My function that saves the images in the folder works properly, but when I open the photos folder the images appear duplicated however with different names Follow the save function:
protected void btnSalvarImovel_Click(object sender, EventArgs e)
{
if (fuFotos.HasFile == false)
lblImovel.Text = "Por favor selecione uma foto!";
else
{
List<string> nomeFoto = new List<string> ();
var arquivos = fuFotos.PostedFiles;
foreach (var arquivo in arquivos)
{
string nomeArquivo = arquivo.FileName;
fuFotos.PostedFile.SaveAs(Server.MapPath("~") + "/Imovel/" + nomeArquivo);
nomeFoto.Add("~/Imovel/" + nomeFoto + nomeArquivo + arquivo.FileName);
}
string comandoSQL = string.Format("INSERT INTO Imovel Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
ddlCidade.SelectedItem.Value, ddlLocalizacao.SelectedItem.Value, ddlOperacao.SelectedItem.Value, ddlTipoImovel.SelectedItem.Value,
txtTitulo.Text, txtObservacao.Text, txtValor.Text, txtQtdQuartos.Text, string.Join(",", nomeFoto));
lblImovel.Text = "Imóvel cadastrado com sucesso!";
ddlCidade.Text = string.Empty;
ddlLocalizacao.Text = string.Empty;
ddlOperacao.Text = string.Empty;
ddlTipoImovel.Text = string.Empty;
txtTitulo.Text = string.Empty;
txtObservacao.Text = string.Empty;
txtValor.Text = string.Empty;
txtQtdQuartos.Text = string.Empty;
try
{
conexaoSQL.Open();
int teste = new SqlCommand(comandoSQL, conexaoSQL).ExecuteNonQuery();
}
finally
{
conexaoSQL.Close();
}
}
}
The photo of the folder:
Since she should have stayed that way:
I noticed at the bank you’re being saved like this:
Does it have anything to do with it? Would anyone know what could be causing this or how to help me fix it? Thanks in advance.
ASP.NET with click event?
– Jéf Bueno
that same follows the aspx
– Thais Ferreira
<div style="margin: 60px 0 5px 600px;"> <Asp:Button ID="btnSalvarImovel" runat="server" Text="Save" Cssclass="btn btn-Success" Onclick="btnSalvarImovel_Click" Accept="image/jpeg" /> </div>
– Thais Ferreira
If you have uploaded the same image several times it should be normal for the server to give different names so that no pictures are deleted. Try giving a unique name to the file.
– Bruno Costa
Hi Bruno, thanks for answering, I edited the question to be a little better understand what is happening. The photos have a unique name each, what happens is that when saving it takes the first one that was selected and half that replaces the contents of the photo, leaving intact only their name
– Thais Ferreira