Streaming File From http

A

Abhishek

Hi! Everyone

I need to stream a file to get the information stored in it
my code is as under

FileStream siteFileStream=null;

XmlTextReader XmlRdr=null;

string fileName=http://online.abc.com/ServerDetails.xml;

//string fileName="C:/Documents and
Settings/Administrator/Desktop/aGOnlineServerDetails.xml",FileMode.Open";

siteFileStream = new
eName",FileMode.Open); --> This Line gives an exception



"System.ArgumentException: URI formats are not supported.\r\n at
System.IO.Path.GetFullPathInternal(String path)\r\n at
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
bFromProxy)\r\n at System.IO.FileStream..ctor(String path, FileMode
mode)\r\n at line 1287"

If I replace the http: path with the local file path it works perfectly

How can i stream this file if it is on the web. I can perfectly access this
file if i type the same path in ie.

Kindly help this is very very urgent


Regards
Abhishek
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You can use System.Net.HttpWebRequest and System.Net.HttpWebResponse to
issue an HTTP request to a Web resource and to obtain the response stream.
 
A

Abhishek

Dmitriy Lapshin said:
Hi,

You can use System.Net.HttpWebRequest and System.Net.HttpWebResponse to
issue an HTTP request to a Web resource and to obtain the response stream.

actually this does not work properly since it slows down the process
considerably.
 
A

Abhishek

Ashish Das said:
how about being nice and telling what you did?

Sure i'll be glad to share it.
Actually i dropped the Filestream object and just put the path directly in
the XMLReader class.
Bingo that worked.
Probably FileStream class works only with local files.

Cheers!
Abhishek
 
J

Joerg Jooss

Abhishek said:
Sure i'll be glad to share it.
Actually i dropped the Filestream object and just put the path
directly in the XMLReader class.
Bingo that worked.

Which is just a neat shortcut for downloading the file via HTTP (see
Dmitriy's post).


Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top