質問

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.

役に立ちましたか?

解決

Please see:

What are the various "Build action" settings in Visual Studio project properties and what do they do?

"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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top