Well... if you are transferring files, you are basically transfering bytes. So a simple way would be to simply return a byte array, which you can then save on the client.
Example:
[WebMethod]
public byte[] GimmeMyFile(string fileName)
{
//Do whatever magic you need to do to get the file and transfer it into a bytestream.
//A simple example is this:
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
byte[] barr = new byte[fs.Length];
fs.Read(barr, 0, fs.Length);
return barr;
}
If you have extremely large files or so many requests you would clog up your ws server memory, you can implement your own mechanism for chunking the file and transferring inidividual chunks. An example:
[WebMethod]
public byte[] GimmeMyFile(string fileName, int offset, int length)
{
//Do whatever magic you need to do to get the file and transfer it into a bytestream.
//A simple example is this:
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
int len = fs.Length;
//If you are requesting bytes beyond file length, abort.
if (offset > len) return new byte[0];
//else get the file
if (len < offset + length)
{
len = len - offset; //if you are at the end of file, you need less bytes.
}
else
{
len = length;
}
byte[] barr = new byte[len];
fs.Read(barr, offset, len);
return barr;
}
This way you would simply keep calling the method with increasing offsett (by the chunk size) until you get back a chunk that's shorter then the chunk size you requested. Then you know you've reached the end of the file.
If you have larger files or narrow communication channels you may consider compressing the file before transfer (and then uncompressing it again on the client); for this Google up SharpZipLib. Works decently fast.
Enjoy!
Regards,
Sigmund Jakhel
MCSD.NET
"Ken" <krcourville_atsign_msn_period_com> wrote in message news:u%****************@TK2MSFTNGP15.phx.gbl...
Can anyone point me to some info, which gives me an idea of how to go
about making an ASP.NET web service to download files
I plan to access the web service from a C# Windows App.
Thanks.
*** Sent via Developersdex http://www.developersdex.com ***