Link to home
Start Free TrialLog in
Avatar of mmalik15
mmalik15

asked on

unable to download file using HttpWebRequest in c#

using a webservice i am trying to download files (*.doc, *.rtf , *.txt etc) but getting the following exception


.GetResponseStream().Length' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}

'httpResponse.GetResponseStream().Position' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}

{"This stream does not support seek operations."} System.SystemException {System.NotSupportedException}

the code i m using is
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create("http://member.goodpractice.net/content.htm" + queryString);

            //Create a response for this request
            HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

            if (fileResp.ContentLength > 0)
            {
                //fileResp.ContentLength = fileResp.ContentLength;

                //Get the Stream returned from the response
                Stream stream = fileResp.GetResponseStream();
            }

Open in new window


The absolute url e.g. (http://member.goodpractice.net/content.htm?GWSUsername=xxx&GWSPassword=xxx&format=4&id=582805c7-6386-0029-b068-9fe900b4c257) works perfectly fine when opened in a browser it would download the file  without any issues. Any ideas what could be wrong with this code
Avatar of SStory
SStory
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Stephan
Stephan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial