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 7051573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:16:47+00:00 2026-05-28T03:16:47+00:00

I use following code to open a file. When I was prompt to open/save

  • 0

I use following code to open a file. When I was prompt to open/save the file, it showed the file was from localhost, but the file could be in a network drive. Is there any way I chould replace the localhost with its actual location?

byte[] bts = System.IO.File.ReadAllBytes(fileName);
            Response.Clear();
            Response.ClearHeaders();
            Response.AddHeader("Content-Type", "Application/octect-stream");
            Response.AddHeader("Content-Length", bts.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment; filename=" + ((LinkButton)sender).Text);
            Response.BinaryWrite(bts);
            Response.Flush();
            Response.End();           

Edit: ((LinkButton)sender).Text) is the filename without path. The actual location of the file is, for example, Y:\SPR_Upload, and Y is a network drive that is mapped to C$(\m6300-7). When I clicked the file, I was prompted Do you want to open or save XXX(24.1KB) from localhost? I want to replace the localhost with m6300-7. How do I do that?

  • 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-05-28T03:16:47+00:00Added an answer on May 28, 2026 at 3:16 am

    The issue appears to be that you’re using

    ((LinkButton)sender).Text
    

    to get the filename. If the LinkButton that’s calling this has localhost hard-coded into its Text value, you’ll have to correct it there.

    If you’ve hard-coded the Text property of your LinkButton to something like http://localhost:0000/...., you’ll need to correct that. With near-zero exceptions, all links in your application should be relative, such as /home/index or /support/default.aspx.

    Note that the Content-Disposition header just sets the filename that the browser uses or presents to the user – it can be set to anything, and doesn’t have to reference a real file on the server.

    As such, if you just want the filename (stripping all path information, etc), you can use

    var fileName = System.IO.Path.GetFileName(((LinkButton)Sender).Text);
    

    then use the resulting value in your Content-Disposition header assignment.

    Update

    When the browser says “Would you like to download xxxx.xx from localhost?”, it gets the server name (localhost in this case) from the URL that is used to download the file. If you run the same app on, say, “www.mysite.com”, the browser will say “Would you like to download xxxx.xx from http://www.mysite.com?” For security reasons, etc, you shouldn’t be able to override the name of the server used in that prompt.

    The Content-Disposition header just sets the filename that the browser shows the user.

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

Sidebar

Related Questions

I wanted to use the following code from here: How can I save all
As of now I use the following python code: file = open(filePath, r) lines=file.readlines()
I use the following code snippet to open a local docx file and it
In a project i use the following code to open a window: window.open(href, 'mysite'
I use the following code to compile a cpp file to object file. g++
I use the following code to layout network drives on a system. I want
I know that to create a file in c++ we use following code #include
when I try to use the following code in the codebehind file, it runs
Assuming a handle created with the following code: use IO::File; my $fh = IO::File->new;
I have the following code: use strict; my $org_file_hash = { 'S6' => '/path/to/file/filename.txt_S6',

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.