Reputation: 283
in c#/mvc project How can we read Content of .HTML file at runtime which is available under "Content" folder in VS project. Not using physical path.
Upvotes: 0
Views: 3890
Reputation: 6220
Please see:
"Content" build action has the resource as a file along with but not embedded within the application, you need to know the physical path (relative or absolute) in order to access it.
So in other words, what you're asking is not possible with the build action set to "Content".
You can set it to an Embedded Resource and access it using:
using (Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Your assembly namespace.your resource folder" + "file1.txt"))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
(lifted from: How to read embedded resource text file)
Where result
will be the HTML file contents as a string.
Upvotes: 2