Click here to Skip to main content
15,909,051 members
Home / Discussions / C#
   

C#

 
Questiondownloading file. in response: "Content-Disposition: attachment; filename="file.gif"" Pin
hello_amigo1-Feb-10 15:46
hello_amigo1-Feb-10 15:46 
Hi. I want to download a file from one website. It is really simple do it like this:
WebClient wc = new WebClient();
wc.DownloadFile(@"http://aaa.uuu", @"D:\111.gig");

But when a file is attachment... in response we have header: "Content-Disposition: attachment; filename="file.gif"", I couldn`n download file.
I`v seached smth around this problem and sow like this:
// Get the physical Path of the file(test.doc)
   string filepath = Server.MapPath("test.doc");
   // Create New instance of FileInfo class to get the properties of the file being downloaded
   FileInfo file = new FileInfo(filepath);
   // Checking if file exists
   if (file.Exists)
   {
    // Clear the content of the response
    Response.ClearContent();
    // LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    // Add the file size into the response header
    Response.AddHeader("Content-Length", file.Length.ToString());
    // Set the ContentType. function "ReturnExtension" return the proper content type and set it to the Response.ContentType property (not in this listing)
    Response.ContentType = ReturnExtension(file.Extension.ToLower());
    // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
    Response.TransmitFile(file.FullName);
    // End the response
    Response.End();
   }

The first problem is what i couldn`t use class Response, becouse i couldn`t use System.Web.UI.
Plz, explain me, I couldn`t use System.Web.UI becouse I programming in C# but not in ASP.NET?
And could anybody help me with downloading file, which is attachment?
AnswerRe: downloading file. in response: "Content-Disposition: attachment; filename="file.gif"" Pin
Not Active1-Feb-10 16:17
mentorNot Active1-Feb-10 16:17 
QuestionDynamic Multiple Dropdown Lists using Access Database Pin
scorpio221-Feb-10 13:44
scorpio221-Feb-10 13:44 
AnswerCross post Pin
Not Active1-Feb-10 16:14
mentorNot Active1-Feb-10 16:14 
GeneralRe: Cross post Pin
scorpio222-Feb-10 1:33
scorpio222-Feb-10 1:33 
GeneralRe: Cross post Pin
Not Active2-Feb-10 1:56
mentorNot Active2-Feb-10 1:56 
GeneralRe: Cross post Pin
scorpio222-Feb-10 2:55
scorpio222-Feb-10 2:55 
QuestionOpen Source Project Pin
programmervb.netc++1-Feb-10 13:06
programmervb.netc++1-Feb-10 13:06 
AnswerRe: Open Source Project Pin
April Fans2-Feb-10 20:18
April Fans2-Feb-10 20:18 
GeneralRe: Open Source Project Pin
programmervb.netc++3-Feb-10 16:17
programmervb.netc++3-Feb-10 16:17 
QuestionSending AT commands to a v.92 USB modem Pin
saeidfarahi1-Feb-10 11:55
saeidfarahi1-Feb-10 11:55 
AnswerRe: Sending AT commands to a v.92 USB modem Pin
Luc Pattyn1-Feb-10 12:10
sitebuilderLuc Pattyn1-Feb-10 12:10 
AnswerRe: Sending AT commands to a v.92 USB modem Pin
PIEBALDconsult1-Feb-10 15:01
mvePIEBALDconsult1-Feb-10 15:01 
GeneralRe: Sending AT commands to a v.92 USB modem Pin
Luc Pattyn1-Feb-10 15:11
sitebuilderLuc Pattyn1-Feb-10 15:11 
Questionrandom in background [modified] Pin
Mark H Bishop1-Feb-10 11:21
Mark H Bishop1-Feb-10 11:21 
AnswerRe: random in background Pin
harold aptroot1-Feb-10 11:39
harold aptroot1-Feb-10 11:39 
AnswerRe: random in background Pin
Abhinav S1-Feb-10 11:43
Abhinav S1-Feb-10 11:43 
GeneralRe: random in background Pin
Mark H Bishop2-Feb-10 4:05
Mark H Bishop2-Feb-10 4:05 
AnswerRe: random in background Pin
Luc Pattyn1-Feb-10 12:11
sitebuilderLuc Pattyn1-Feb-10 12:11 
Questionhow to expose an event in user control Pin
nuttynibbles1-Feb-10 10:37
nuttynibbles1-Feb-10 10:37 
AnswerRe: how to expose an event in user control Pin
#realJSOP1-Feb-10 10:47
professional#realJSOP1-Feb-10 10:47 
AnswerRe: how to expose an event in user control Pin
DaveyM691-Feb-10 12:10
professionalDaveyM691-Feb-10 12:10 
GeneralRe: how to expose an event in user control Pin
nuttynibbles1-Feb-10 16:51
nuttynibbles1-Feb-10 16:51 
QuestionAdding and removing differences from List compared to another list Pin
zagitta1-Feb-10 10:34
zagitta1-Feb-10 10:34 
AnswerRe: Adding and removing differences from List compared to another list Pin
#realJSOP1-Feb-10 10:51
professional#realJSOP1-Feb-10 10:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.