I have the following to show an image when loading it with the AsyncFileUpload, the problem that I have is that it saves the image in the route that I put it, but I would like that route to be temporary because to save it I want to occupy the button, I can not find a way to show the images without saving the file and that is because it occupies memory and I can not delete it also in my folder I have twice the same file once I press the button
asp.net Code
<div class="col-xs-6 col-md-4">
<!-- imagen 1-->
<div class="thumbnail">
<asp:Image class="imgpub" src="../img/ico_img.png" ID="displayImage" runat="server" />
<ajaxToolkit:AsyncFileUpload PersistFile="true" class="pruebaos" ID="AsyncFileUpload2" runat="server" OnClientUploadComplete="uploadComplete" OnUploadedComplete="FileUploadComplete" />
<script type="text/javascript">
function uploadComplete(sender, args) {
var imageName = args.get_fileName();
$get("displayImage").src = "<%=ResolveUrl(UploadFolderPath) %>" + imageName;
}
</script>
</div>
</div>
<div class="col-xs-6 col-md-4">
<!-- imagen 2-->
<div class="thumbnail">
<asp:Image class="imgpub" src="../img/ico_img.png" ID="Image1" runat="server" />
<ajaxToolkit:AsyncFileUpload PersistFile="true" class="pruebaos" ID="AsyncFileUpload3" runat="server" OnClientUploadComplete="uploadComplete2" OnUploadedComplete="FileUploadComplete2" />
<script type="text/javascript">
function uploadComplete2(sender, args) {
var imageName = args.get_fileName();
$get("Image1").src = "<%=ResolveUrl(UploadFolderPath2) %>" + imageName;
}
</script>
</div>
</div>
<div class="form-group">
<asp:Button ID="btn_gua_rda" runat="server" UpdateMode="Conditional" class="btn-full btn-lg btn-blue" Text="Publicar" onclick="btn_gua_rda_Click" ></asp:Button>
</div>
</div>
<asp:UpdatePanel ID="updboton" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_gua_rda" />
</Triggers>
</asp:UpdatePanel>
This is the server side code to show the image:
protected string UploadFolderPath = "~/images/alquilerimagenes/";
protected void FileUploadComplete(object sender, EventArgs e)
{
string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
AsyncFileUpload1.SaveAs(Server.MapPath(this.UploadFolderPath) + filename);
}
protected string UploadFolderPath2 = System.IO.Path.GetTempPath();
protected void FileUploadComplete2(object sender, EventArgs e)
{
string filename2 = System.IO.Path.GetFileName(AsyncFileUpload2.FileName);
AsyncFileUpload2.SaveAs(Server.MapPath(this.UploadFolderPath2) + filename2);
}
and for the button click event, the one that keeps the database has the following code (I would like it to be saved when you click on the image), not when you see it on my page
protected void btn_gua_rda_Click(object sender, EventArgs e)
{
//Insertar Imagenes
if (AsyncFileUpload1.HasFile)
{
string SavePath = Server.MapPath("~/images/alquilerimagenes/") + va_cod_pub;
if (!Directory.Exists(SavePath))
{
Directory.CreateDirectory(SavePath);
}
string extencion = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
AsyncFileUpload1.SaveAs(SavePath + "\" + tb_tit_pub.Text.ToString().Trim() + "01" + extencion);
//guarda en la base de datos
o_ima001._02(tb_tit_pub.Text.ToString().Trim() + "01", extencion, va_cod_pub.ToString());
}
if (AsyncFileUpload2.HasFile)
{
string SavePath = Server.MapPath("~/images/alquilerimagenes/") + va_cod_pub;
if (!Directory.Exists(SavePath))
{
Directory.CreateDirectory(SavePath);
}
string extencion = Path.GetExtension(AsyncFileUpload2.PostedFile.FileName);
AsyncFileUpload2.SaveAs(SavePath + "\" + tb_tit_pub.Text.ToString().Trim() + "02" + extencion);
//guarda en la base de datos
o_ima001._02(tb_tit_pub.Text.ToString().Trim() + "02", extencion, va_cod_pub.ToString());
}
}