Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:17:17+00:00 2026-06-08T07:17:17+00:00

I have made a page that allows users to upload files to the server

  • 0

I have made a page that allows users to upload files to the server using a FileUpload Control and handling its event with this code

Sub SaveAttachment()
    Dim root As String = "C:\temp\"
    Dim filename As String = FileUpload1.FileName
    Dim SaveName As String = root & filename
    FileUpload1.SaveAs(SaveName)
End Sub

That worked fine, I was able to see files getting uploaded, and the content of the files is intact (exactly a duplicate copy of the file that the user’s upload).

Now for downloading the files back to the user (at a later time) I have written another page that reads the file name from a Request.Parameter (“file”) and fetches that file to be downloaded to the user. I have written the Download.aspx page to handle downloading in the ASP part (no code behind was used):

<%@ Import Namespace="System.IO"%>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

        Dim root As String = "C:\temp\"
        Dim filepath As String = Request.Params("file")
        If Not filepath Is Nothing Then
            filepath = root & filepath
            If File.Exists(filepath) And filepath.StartsWith(root) Then
                Dim filename As String = Path.GetFileName(filepath)
                Response.Clear()
                Response.ContentType = "application/octet-stream"
                Response.AddHeader("Content-Disposition", _
                  "attachment; filename=""" & filename & """")
                Response.Flush()
                Response.WriteFile(filepath)
            End If
        End If

End Sub
</script>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>

I tried uploading images files and then downloading them again, and it worked fine. However, only when I upload text files that I get the content of that file appended with some HTML content.

Here is a sample file that I have uploaded
Original File before uploading

Here is my sample text file

It consists of 3 lines only

And here is the file when I downloaded it back
The same file when downloaded from the server

Here is my sample text file

It consists of 3 lines only
<form name="form1" method="post" action="FileDownload.aspx?file=sample_file.txt" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5NTU5ODQyNTBkZNCYbOVZJDRUAOnIppQYkwHUSlb0" />
</div>

<span id="Label1">Label</span>
</form>

I went to the file on the server and opened it to make sure that the additional HTML content was there, but as I said, the file was uploaded perfectly. Only when it is downloaded does it contain appended HTML stuff.

What is it that I am doing wrong? What can I do to make this additional HTML code go away?
Why does this problem only affect Text file, not images, EXE, XLS, DOC ,, etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:17:20+00:00Added an answer on June 8, 2026 at 7:17 am

    Make sure to end your Response by calling Response.End() after Response.WriteFile(filepath) or else your form will be appended to the stream and sent to the client.

    It will affect other files as well though most likely only be seen as garbage at the end of the file and ignored by their respective applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a page that allows users to view a list of batch files
I have a wordpress blog. I made a custom page-template that allows users to
I have made a user control that allows an image to be uploaded and
I have made a php page that sends an email message with multiple attachments.
I have made a web application that uses master page for Login & Logout
I have made a page in which i m using a list to display
I have made a kind of CMS using CodeIgniter. It loads the page content
Say we have a Django page that shows a list of items and allows
I have been developing a service that allows users to insert information from my
I have to made a page which will send Email to Newsletter subscribers. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.