Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

I am using following code for file deletion on server after downloading at client site.

The code is working from visual studio but NOT working when website is hosted even on the coding machine.

C#
Dim filefullname As System.IO.FileInfo = New System.IO.FileInfo(theFileName)
                Response.Clear()
                Response.AddHeader("Content-Disposition", "attachment; filename=Observation_Report.docx")
                Response.AddHeader("Content-Length", filefullname.Length.ToString())
                Response.ContentType = "application/octet-stream"
                Response.WriteFile(filefullname.FullName)
                Response.Flush()
                System.IO.File.Delete(theFileName)
                Response.End()
Posted
Updated 23-Dec-15 15:21pm
v2
Comments
Suvendu Shekhar Giri 23-Dec-15 21:50pm    
Put a breakpoint and debug to find out what is the value hold by filefullname.FullName. Is it the fully qualified path?
atul sharma 5126 23-Dec-15 21:59pm    
Thanks for the reply!
I have checked and the path is correct. Infact filefullname.fullname and thefilename are same.
Also code is working fine when pkg run from VS but when hosted, the file is not deleted.
Prasad Avunoori 24-Dec-15 6:08am    
File deletion on IIS host server requires permission. Do the identity impersonation to user who has admin permissions.

1 solution

First off, I'll bet the error tells you exactly what the problem is. However, I'd bet it's a permissions issue since it works on your machine but not hosted. You'll need to grant whatever account is hosting the IIS application pool the proper permissions to delete files from that path.
 
Share this answer
 

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