• 0

[ASP.NET(VB)] Server File Storage


Question

Okay... lets see how good you self-proclaimed neowin geeks are... ;)

i have a unique situation... well, prolly not that unique but here goes. Our webhost does not allow the uploading or storage of executable files... (.exe, .com, .bat, etc). However, it's hard to tell your customers that they need to rename their files after downloading them. So here's what i'm trying to do...

we're uploading the files with .BMF extensions. I'd like to get them to rename themselves for the download... all i get is an error stating that:

Could not find file "c:\inetpub\wwwroot\download\test.EXE".

Sub Page_Load()
	lblMsg.Text = nothing
	dim F as New FileInfo(request.QueryString("F"))
	If File.Exists(F.FullName) Then
 ?SendFile(GetFile(F), F)
	Else
 ?lblMsg.Text = "File Not Found."
	End If
End Sub

Function GetFile(ByVal F as FileInfo)
	const EXE as string = ".EXE" 'executeable file extension - host won't allow.
	dim FN as string = F.Name
	Return Path.ChangeExtension(FN,EXE)
End Function

Sub SendFile(ByVal FN as string, ByVal F as FileInfo)
	Response.Clear()
	Response.AddHeader("Content-Disposition","attachment; filename=" & F.Name)
	Response.AddHeader("Content-Length", F.Length.ToString())
	Response.ContentType = "application/octet-stream"
	Response.WriteFile(Path.ChangeExtension(FN,".EXE"))
 ? ? ? ? ? ? ? ?Response.Flush()
End Sub

Link to comment
https://www.neowin.net/forum/topic/138621-aspnetvb-server-file-storage/
Share on other sites

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.