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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:43:42+00:00 2026-06-14T08:43:42+00:00

I have files on a server that can be accessed from a URL formatted

  • 0

I have files on a server that can be accessed from a URL formatted like this:
http:// address/Attachments.aspx?id=GUID

I have access to the GUID and need to be able to download multiple files to the same folder.

if you take that URL and throw it in a browser, you will download the file and it will have the original file name.

I want to replicate that behavior in C#. I have tried using the WebClient class’s DownloadFile method, but with that you have to specify a new file name. And even worse, DownloadFile will overwrite an existing file. I know I could generate a unique name for every file, but i’d really like the original.

Is it possible to download a file preserving the original file name?

Update:

Using the fantastic answer below to use the WebReqest class I came up with the following which works perfectly:

    public override void OnAttachmentSaved(string filePath)
    {
        var webClient = new WebClient();

        //get file name
        var request = WebRequest.Create(filePath);
        var response = request.GetResponse();
        var contentDisposition = response.Headers["Content-Disposition"];
        const string contentFileNamePortion = "filename=";
        var fileNameStartIndex = contentDisposition.IndexOf(contentFileNamePortion, StringComparison.InvariantCulture) + contentFileNamePortion.Length;
        var originalFileNameLength = contentDisposition.Length - fileNameStartIndex;
        var originalFileName = contentDisposition.Substring(fileNameStartIndex, originalFileNameLength);

        //download file
        webClient.UseDefaultCredentials = true;
        webClient.DownloadFile(filePath, String.Format(@"C:\inetpub\Attachments Test\{0}", originalFileName));            
    }

Just had to do a little string manipulation to get the actual filename. I’m so excited. Thanks everyone!

  • 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-14T08:43:43+00:00Added an answer on June 14, 2026 at 8:43 am

    As hinted in comments, the filename will be available in Content-Disposition header. Not sure about how to get its value when using WebClient, but it’s fairly simple with WebRequest:

    WebRequest request = WebRequest.Create("http://address/Attachments.aspx?id=GUID");
    WebResponse response = request.GetResponse();
    string originalFileName = response.Headers["Content-Disposition"];
    Stream streamWithFileBody = response.GetResponseStream();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small app that downloads some files from a remote (HTTP) server
I have a server that is serving files to several windows clients using the
I have a home-grown HTTPS server that serves up simple files (it's embedded within
I have a PHP script running on my LAMP server that requires certain files
I have a folder on my remote server that has a few .png files
I have a folder on my web server that has hundreds of mp3 files
I have a modal window that uploads files to server. Works great. Upon completion
I'm building an application with a self-contained HTTP server which can be either accessed
I have created a HTTP file server with the objective of transferring media files
I have a program that fetches a file from a server and downloads it.

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.