Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have an application in which user upload the image and it stores in temp folder to work on it. When process on image got complete, image downloads to the user pc and delete from the temp folder. For that i have coded below
C#
//upload the image
FileUpload1.SaveAs(Server.MapPath("~/temp/") + FileUpload1.FileName)
 //coading to process on uploaded image
        
//download file
        Me.Response.AddHeader("content-disposition",       String.Format("attachment;filename={0}", Path.GetFileName(FileUpload1.FileName)))
        Me.Response.ContentType = "image/jpg"
        Me.Response.WriteFile(Server.MapPath("~/temp/") + FileUpload1.FileName)

// delete the file from temp
        
File.Delete(Server.MapPath("~/temp/") + FileUpload1.FileName)

Now, when i write this code, and run the application it is not getting error but also not downloading or deleting the file. This both functions are works fine separatly but when i put download and after delete together i face the problem... can any one have any idea of this and help me out...??? Thanks in advance...
Posted
Updated 2-Jul-12 18:09pm
v3
Comments
[no name] 3-Jul-12 0:15am    
I am not sure, but are you sure, your file is not getting deleted as soon as it creates. That is why you are not able to see file exists in temp folder.
AmitGajjar 3-Jul-12 0:36am    
after downloading your file, clear the response and try again.
Zoltán Zörgő 3-Jul-12 0:46am    
Have you tried to trace step by step?
Naikniket 3-Jul-12 1:13am    
yup i have solved it.... it's just easy... :) :)

Response.Flush()
System.IO.File.Delete(fullPathFileName)
Response.[End]()

1 solution

Its not directly delete from that .
till just check that it help you :

VB
Response.Flush();
System.IO.File.Delete(fullPathFileName);
Response.[End]();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900