473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Downloading file from remote server with 'Save As' dialogue

Hi,

Any help with this would be really appreciated!

I'm trying to download a file from a remote server. The access
permissions is okay but the problem I'm facing is that the file is
getting downloaded before the Save As dialogue appears. As we will be
downloading some large files, it's unpractical to have this.

So far the code I have to download the file is

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData =
wc.DownloadData(@"http://<remote-server>/media/mySummerHoliday.wmv"));
Response.ContentType="application/wmv";
Response.AddHeader( "content-disposition","attachment;
filename=encryptedindy.wmv");

But as I said this downloads the media before the 'Save As' dialogue.

I also have some code that will save the media from my local drive

FileStream sourceFile = new
FileStream(@"C:\media\mySummerHoliday.wmv", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.ContentType="wmv";
Response.AddHeader( "content-disposition","attachment;
filename=mySummerHoliday.wmv");
Response.BinaryWrite(getContent);

But, I've not been able to modify this to download from a remote
server.

I'm sure I'm missing a trick here somewhere. Any ideas?

Regards,
Kevin
Nov 16 '05 #1
5 6837
Hi,

Try changing the ContentType to "application/octet-stream".

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"kevin" <ke********@hotmail.com> wrote in message
news:8c**************************@posting.google.c om...
Hi,

Any help with this would be really appreciated!

I'm trying to download a file from a remote server. The access
permissions is okay but the problem I'm facing is that the file is
getting downloaded before the Save As dialogue appears. As we will be
downloading some large files, it's unpractical to have this.

So far the code I have to download the file is

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData =
wc.DownloadData(@"http://<remote-server>/media/mySummerHoliday.wmv"));
Response.ContentType="application/wmv";
Response.AddHeader( "content-disposition","attachment;
filename=encryptedindy.wmv");

But as I said this downloads the media before the 'Save As' dialogue.

I also have some code that will save the media from my local drive

FileStream sourceFile = new
FileStream(@"C:\media\mySummerHoliday.wmv", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.ContentType="wmv";
Response.AddHeader( "content-disposition","attachment;
filename=mySummerHoliday.wmv");
Response.BinaryWrite(getContent);

But, I've not been able to modify this to download from a remote
server.

I'm sure I'm missing a trick here somewhere. Any ideas?

Regards,
Kevin


Nov 16 '05 #2
I'm afriad changing the ContentType to "application/octet-stream"
results in the same behaviour where the media is downloaded before the
'Save As' dialogue opens.

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData
=wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv"));
Response.ContentType="application/octet-stream";
Response.AddHeader(
"content-disposition","attachment;filename=mySummerHoliday. wmv");

I think I need to read the data into FileStream, but that only seams to
take physical paths and not URIs.

Regards,
Kevin

Nov 16 '05 #3
Kevin,

You might want to try adding the content disposition header to the
response stream, like so:

// Add the content disposition header to the response.
Response.AddHeader("content-disposition", "attachment; filename=" +
pstrFileName);

Where pstrFileName is the name of the file you want to recommend to save
as.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ke********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm afriad changing the ContentType to "application/octet-stream"
results in the same behaviour where the media is downloaded before the
'Save As' dialogue opens.

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData
=wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv"));
Response.ContentType="application/octet-stream";
Response.AddHeader(
"content-disposition","attachment;filename=mySummerHoliday. wmv");

I think I need to read the data into FileStream, but that only seams to
take physical paths and not URIs.

Regards,
Kevin

Nov 16 '05 #4

Hi Nicholas,

Cheers, but I already have the content disposition header in. In this
case I just made called the file mySummerHoliday.wmv.

WebClient wc = new WebClient();
byte[] byteData;
Response.ContentType="application/octet-stream";
Response.AddHeader(
"contentdisposition",
"attachment;filename=mySummerHoliday.wmv");
Response.BinaryWrite(byteData
= wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv"));

What I'm trying to achieve is that it streams in the 'Save As' dialogue
but with my current code it get's downloaded to the page before the
'Save As' dialogue.

Then the 'Save As' dialogue appears and it says it's saved a 4MB file
in 1 second.

I only want the content to be downloaded once you click 'Save' as in
all web based downloads.

I know this should be pretty simple I just can't work it out!

Regards,
Kevin
Nicholas Paldino [.NET/C# MVP] wrote:
Kevin,

You might want to try adding the content disposition header to the response stream, like so:

// Add the content disposition header to the response.
Response.AddHeader("content-disposition", "attachment; filename=" +
pstrFileName);

Where pstrFileName is the name of the file you want to recommend to save as.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ke********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm afriad changing the ContentType to "application/octet-stream"
results in the same behaviour where the media is downloaded before the 'Save As' dialogue opens.

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData
=wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv")); Response.ContentType="application/octet-stream";
Response.AddHeader(
"content-disposition","attachment;filename=mySummerHoliday. wmv");

I think I need to read the data into FileStream, but that only seams to take physical paths and not URIs.

Regards,
Kevin


Nov 16 '05 #5
Kevin:

I think that the problem is that you are writing all the data at once in the
response stream and while the user is taking their time to click on the
"Save As" button, browser is downloading the data in the background.
Remember that IE downloads the files to a temp location and then moves it if
the user chooses to save it to a different location. With or without "Save
As" browser will always download the file to the local cache.

May be you can download the file from the remote server (say 192.168.16.133)
into a temp file on your local server and then redirect the response to this
temp file. This is better for performance anyway because then you are
letting the web server do what it does best -- i.e., serve static files.

Cheers,
Shariq Khan
<ke********@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

Hi Nicholas,

Cheers, but I already have the content disposition header in. In this
case I just made called the file mySummerHoliday.wmv.

WebClient wc = new WebClient();
byte[] byteData;
Response.ContentType="application/octet-stream";
Response.AddHeader(
"contentdisposition",
"attachment;filename=mySummerHoliday.wmv");
Response.BinaryWrite(byteData
= wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv"));

What I'm trying to achieve is that it streams in the 'Save As' dialogue
but with my current code it get's downloaded to the page before the
'Save As' dialogue.

Then the 'Save As' dialogue appears and it says it's saved a 4MB file
in 1 second.

I only want the content to be downloaded once you click 'Save' as in
all web based downloads.

I know this should be pretty simple I just can't work it out!

Regards,
Kevin
Nicholas Paldino [.NET/C# MVP] wrote:
Kevin,

You might want to try adding the content disposition header to

the
response stream, like so:

// Add the content disposition header to the response.
Response.AddHeader("content-disposition", "attachment; filename=" +
pstrFileName);

Where pstrFileName is the name of the file you want to recommend

to save
as.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ke********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
> I'm afriad changing the ContentType to "application/octet-stream"
> results in the same behaviour where the media is downloaded before the > 'Save As' dialogue opens.
>
> WebClient wc = new WebClient();
> byte[] byteData;
> Response.BinaryWrite(byteData
> =wc.DownloadData(@"http://192.168.16.133/media/mySummerHoliday.wmv")); > Response.ContentType="application/octet-stream";
> Response.AddHeader(
> "content-disposition","attachment;filename=mySummerHoliday. wmv");
>
> I think I need to read the data into FileStream, but that only seams to > take physical paths and not URIs.
>
> Regards,
> Kevin
>

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Raymond H. | last post by:
Hello, I tried the line in vb but it open the dialogue box (I'd like not to open this box; I'd like save without viewing a dialogue box). WebBrowser1.ExecWB OLECMDID_SAVEAS,...
1
by: Kajol | last post by:
Hi I am facing a strange problem in downloading files from the web. CASE 1: I have an ActiveX.dll file developed using Visual Basic 6.0 and uploaded on a Linux Server. I am typing...
1
by: Keith | last post by:
I have a minor problem with a piece of code I have written to download a CSV file in an ASP.NET application. It works fine except that if the user presses the Open button on the IE6 download...
7
by: Wardeaux | last post by:
Hey all, I'm hitting a wall... We have many daily reports generated on another server, need to present list of available files and allow user to download desired files from aspx page... any...
4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
5
by: roland.groenvynck | last post by:
I try to build my first web form application with C#. I want to program the downloading of a file to the client . Therefore I can use WebClient.DownloadFile (url, filepath ); I would like that...
0
by: Burak Gunay | last post by:
Hello, I am using the code below to enable a user save a dbf (foxpro) file that resides ona web server to their own pc. Response.ContentType = "application/octet-stream"...
1
by: Vic Spainhower | last post by:
Hello, I am trying to download a file to my local machine using PHP. However, when the script runs the file is placed in the folder assigned to the ftp user on the Web server instead of...
1
by: Muddasir | last post by:
Hello everyone. I am facing problem in downloading .xls file. I generate report and save data in excel sheet on server. and once user click the 'save data in excel format', an excel sheet is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.