dev_intagleo
asked on
create a stream from a URL and then write that stream to response
Hi,
I have a URL in a string and there is a file at that URL lets say abc.com/file.js
Now, i want to load that file in a stream (i think by byte array) and then reponse.write on the page
so that file.js or any other text file appeared on the page.
So far my code is
path variable contains the url
currently its giving me error
"System.NotSupportedExcept ion: This stream does not support seek operations."
on Line
I have a URL in a string and there is a file at that URL lets say abc.com/file.js
Now, i want to load that file in a stream (i think by byte array) and then reponse.write on the page
so that file.js or any other text file appeared on the page.
So far my code is
path variable contains the url
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(path);
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream str = WebResp.GetResponseStream();
int byteCount = (int)str.Length;
byte[] fileBytes = new byte[byteCount];
str.Read(fileBytes, 0, byteCount);
Response.ClearContent();
Response.ClearHeaders();
Response.BinaryWrite(fileBytes);
Response.End();
currently its giving me error
"System.NotSupportedExcept
on Line
int byteCount = (int)str.Length;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And if you want to write to the server then you must to use the post method in a separate request.
WebReq.Method = "POST";
Also I recommend you to explore the System.Net.WebClient class, it is very useful for what you want to do, and simple.
Reference:
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
Reference:
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
Open in new window