views:

208

answers:

3

i am trying to use this code:

<%= File.ReadAllText(Server.MapPath("Members/newsletters/welcome.html"))%>

which works great but now the welcome.html file has moved onto another server so i need to read it from an external URL .

any suggestions?

+1  A: 

Have a look at the HttpWebRequest class in .NET (there's an example at that URL or have a look at this blog).

Dan Diplo
i dont see how this would help me at all?
ooo
You want to read a file from an external server? Then that is how you do it, via an HTTP request to a (publicly accessible) URL. How do you think web-browsers work?
Dan Diplo
+1  A: 

You need to be more specific. Are you trying to read it from an UNC path or over the web? Is the other on your network?

If UNC path, probably easiest to map a drive on your local server so it looks like a local file.

Of course, I'm wondering why you're doing it this way at all. Why not replicate the content to all web servers? Reading over network is expensive. Also, that logic should probably be encapsulated in a helper method which can handle caching. You might consider moving the logic to retrieve that content to your controller. A view should render the model data given to it.

Haacked
A: 

try this:

WebClient WebClient = new WebClient();
string YourContent = WebClient.DownloadString(YourUrl);
n26
when i do this i get the following error: base {System.SystemException} = {"This operation requires IIS integrated pipeline mode."}
ooo