Consider the following code in Button1_Click
Dim stFile as String = IO.Path.Combine(Server.MapPath("~/"), "uploads/text/file1.txt")
If IO.File.Exists(stFile) Then
' Do some processing
End If
Exists always returns false in the above code block
And here is Button2_Click code block
Dim stFile as String = IO.Path.Combine(Server.MapPath("~/"), "uploads/text/file1.txt")
Response.Clear()
Response.ContentType = "text/plain"
Response.AppendHeader("content-disposition", "attachment;filename=abc.txt")
Response.TransmitFile(stFile)
Response.Flush()
End If
This always downloads the same file. What could be the problem?
I also crumbled with this issue a while ago and found that the use of "/" and special chars may produce this scenario.
Path.Combine always returns paths with "\".
Try changing uploads/text/file1.txt to uploads\text\file1.txt
If you are generating dynamic file names then try to avoid including any special characters which may require url encoding such as %, (, [space] etc.
(Some concepts may seem illogical in this post but using the combination of \, / and special chars wasted almost 8-10 hours of mine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With