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 5 6845
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
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
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
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
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 > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |