开发者

How to read the contents of a file opened from a virtual path?

I have a static file that exists in a folder in the root of my web application, which gets updated regularly by a 3rd party. I'd like to read the contents of this with a HtmlHelper and inject the contents into my View.

I have the following code:

public static string LoadMyFile(this HtmlHelper htmlHelper)
{
    var virtualPath = VirtualPathUtility.ToAbsolute(string.Format("~/XYZ/myFile.asp"));

    return "";
}

where virtualPath contains the value /XYZ/myFile.asp

How can I read the contents of this in my Html Helper, so that I can inject the contents into the View?

note: just to explain, the myFile.asp is something that we have no control over in 开发者_开发百科terms of the contents, the name or when it's updated. We can only control where it exists. As such, we're keeping it in the root of the application so that it can be accessed with the virtual path.


You can use the IO.File utility.

Example File.Open(Server.MapPath("~/XYZ/myFile.asp"))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜