473,569 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Download

Hey Guys
I have a web application that allows users to download files. But the files
are not hosted on the webserver. The files are stored on external servers and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.
Jan 13 '06 #1
6 2692

"Jatin" <Ja***@discussi ons.microsoft.c om> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #2
You are one the right track. You can string bytes to the client. If the
file is large, then just read and write chunks. You would want to use the
HttpWebRequest which exposes the source stream. i am not sure but I do not
think that it downloads the entire file. I would imagine that it is
buffered.

"Jatin" <Ja***@discussi ons.microsoft.c om> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #3
Hey peter
Need more help:

WebClient client = new WebClient();
Stream st = client.OpenRead (@"http://cre8object.biz. tm/testing/hello.avi");

Apparently this doesnt return me a stream. Also like i earlier said if i
used the client.download Data methid it returns me a byte array. which is file
since i say stream it down response but the problem is that for large files
the Byte array could be large and in memory....

Can you reiterate on how i would use the httpwebrequest?

Thx and hope to hear from you


"Peter Rilling" wrote:
You are one the right track. You can string bytes to the client. If the
file is large, then just read and write chunks. You would want to use the
HttpWebRequest which exposes the source stream. i am not sure but I do not
think that it downloads the entire file. I would imagine that it is
buffered.

"Jatin" <Ja***@discussi ons.microsoft.c om> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.


Jan 13 '06 #4
One method you could use is to create as Web Service on the server hosting
the files. The a request can be made to your public server where an aspx
page will do any necessary processing to check there allowed to download the
requested file or not. The aspx page then set the response header
context-type to text/html, image/gif etc. or whatever you data file is.

Using SAOP you can then connect to your file server and request the file.
This will stream the file across in predefined chunks, which you write
direct to the response buffer and flush the results. You then request the
next chunk through the web service interface until the entire file has been
transferred. The method of requesting the next buffer can be accomplished in
several ways but by far the simplest is to use the current offset. For
example offset of 0 will send the first chunk of the file and you increment
the position by the size of the buffer until the entire file has been
received. This will allow the client side (web server) to specify the size
of the buffer as well so you can control the speed at which the user
receives the file. i.e. The higher the user status the faster you will try
and stream the file to them.

- Mike

---------------------------------------------------------------------------------
http://www.cogitar.net "> Cogitar Software. ( http://www.cogitar.net )
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://www.shop-dominion.com (senery landscape picture gallery)
---------------------------------------------------------------------------------
"Jatin" <Ja***@discussi ons.microsoft.c om> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #5
Hi Mike
Yea sounds like a good idea. I didnt think of the solution in that
perspective. I think i will keep this solution handy if all fails. I am
reluctant well the client might be reluctant to put up a webservice. so im
going to hold on to this.

Ideally i would really like to just stream it directly. If you see my reply
to the 'Peter' you will see i am trying to get it working with the webclient,
or any other alternative

Thanks a bunch Mike

"Mike" wrote:
One method you could use is to create as Web Service on the server hosting
the files. The a request can be made to your public server where an aspx
page will do any necessary processing to check there allowed to download the
requested file or not. The aspx page then set the response header
context-type to text/html, image/gif etc. or whatever you data file is.

Using SAOP you can then connect to your file server and request the file.
This will stream the file across in predefined chunks, which you write
direct to the response buffer and flush the results. You then request the
next chunk through the web service interface until the entire file has been
transferred. The method of requesting the next buffer can be accomplished in
several ways but by far the simplest is to use the current offset. For
example offset of 0 will send the first chunk of the file and you increment
the position by the size of the buffer until the entire file has been
received. This will allow the client side (web server) to specify the size
of the buffer as well so you can control the speed at which the user
receives the file. i.e. The higher the user status the faster you will try
and stream the file to them.

- Mike

---------------------------------------------------------------------------------
http://www.cogitar.net "> Cogitar Software. ( http://www.cogitar.net )
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://www.shop-dominion.com (senery landscape picture gallery)
---------------------------------------------------------------------------------
"Jatin" <Ja***@discussi ons.microsoft.c om> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.


Jan 13 '06 #6
Hey guys
Thx guys. I got the download thing working. Here is the code im using for
anyone else with the same problem:
Stream st = null;

WebClient client;

try

{
client = new WebClient();
string filePath = @"http://XYZ/temp/files/COUNT24.AVI";
st = client.OpenRead (filePath);
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ;
filename=" + filename);
int length;
bool completed = true;
byte[] buffer = new Byte[10000];

while (st.CanRead && completed == true)
{
length = st.Read(buffer, 0, 10000);
Response.Output Stream.Write(bu ffer, 0, length);
Response.Flush( );
buffer = new Byte[10000];
if(length==0)
{
completed = false;
}
}
}
catch
{
//Response.Write( "Error : " + ex.Message);
}
finally
{
if (st != null)
{
st.Close();
}
}
"Jatin" wrote:
Hey Guys
I have a web application that allows users to download files. But the files
are not hosted on the webserver. The files are stored on external servers and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #7

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

Similar topics

5
6098
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily downloads. It uses fpassthru() and some headers() to send a file to the requesting user. The get.php file that I wrote (the file download module if you...
0
1819
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog window. Well, thanks to Steve Orr, I have that working. However, I still have a few issues. First, the download dialog does not have the name of the...
1
5364
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried,...
0
1733
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring, identifies the template required then uses Response.AppendHeader to amend the response to create the file download dialogue. On my local machine this works...
4
2319
by: Nathan Sokalski | last post by:
I want to give visitors to my site the option of downloading a generated ..txt file by clicking a button. I know how to generate text files, but how do I cause the browser to pop up one of those dialog boxes that says something like "Do you want to download FILEX.txt?" I want the user to be able to download the file rather than have the file...
3
2125
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. The problem is that when you run the program it gets to the: Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name)
16
3228
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will not print in the username or email amddress of the person doing the download - which I am collecting from a form on the previous page. I can get...
35
9312
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
4
2413
by: Roberto Mora | last post by:
I have not done programming in a very long time and what is worst, I never learned VB. Although my job does not require this knowledge, I cam across a problem that although it seemed simple it has become a nightmare. There is a log that gets generated in a regular basis and need to put most , but not all its contents in a DB (new or...
1
47390
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.