Download file within WebService

Results 1 to 2 of 2

Thread: Download file within WebService

  1. #1
    Join Date
    Dec 1969

    Default Download file within WebService

    Can anybody point me to a article on how to download a file from within my WebService onto the Web Server. The Web Service receives a Url pointing to the file e.g. "".<BR><BR>Thanx<BR><BR>Jack

  2. #2
    Join Date
    Dec 1969

    Default RE: Download file within WebService

    you dont really need any articles, maybe this code will help you out<BR><BR> HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(tmpURL);<BR> WebResponse Response = myReq.GetResponse();<BR> if (Response.ContentLength&#062;0)<BR> byte[] FileData = GetData(Response.GetResponseStream(),Response.Cont entLength);<BR> else<BR> return -1;<BR><BR> public byte[] GetData(Stream IncomingStream,long paramLength)<BR> {<BR> byte[] mData = null;<BR> if ((IncomingStream.CanRead) && (paramLength &#062; 0))<BR> {<BR> int numBytesToRead = (int) paramLength;<BR> int numBytesRead = 0;<BR> byte[] mData = new byte[paramLength];<BR><BR> while (numBytesToRead &#062; 0) <BR> {<BR> // Read may return anything from 0 to numBytesToRead.<BR> int n = IncomingStream.Read(mData, numBytesRead, numBytesToRead);<BR> if (n==0) // We&#039;re at EOF<BR> break;<BR> numBytesRead += n;<BR> numBytesToRead -= n;<BR> }<BR> IncomingStream.Close();<BR> //IncomingStream.Read(mData,0,(int)paramLength);<BR> } <BR> return mData;<BR> }<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts