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().Lengt h' threw an exception of type 'System.NotSupportedExcept ion' long {System.NotSupportedExcept ion}
'httpResponse.GetResponseS tream().Po sition' threw an exception of type 'System.NotSupportedExcept ion' long {System.NotSupportedExcept ion}
{"This stream does not support seek operations."} System.SystemException {System.NotSupportedExcept ion}
the code i m using is
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
.GetResponseStream().Lengt
'httpResponse.GetResponseS
{"This stream does not support seek operations."} System.SystemException {System.NotSupportedExcept
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();
}
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://social.msdn.microsoft.com/Forums/nl/csharplanguage/thread/4f934429-08f4-464d-b028-ab4936029eb9