Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

c# - How to Store Hta/Html File in Project Resources and Use in Program

I have added an .hta file to my applciation's resources like so:

enter image description here

And I would like to display this by using the line:

Process.Start("explorer.exe", @"PathToFile.hta");

This works when the file is on my system, but when I try displaying the .hta with:

Process.Start("explorer.exe", Properties.Resources.htatest);

I see this error:

There is no program associated to perform the requested action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.

Is it possible to store an .hta in my project resources and then call it from the Program?

For reference, here is the code which exists inside the .hta:

<html>
    <head>
        <title>IT Support - Message</title>
    </head>
    <script language = "VBScript">
        window.setInterval "setfocus()", 100
        Function setfocus
            window.focus()
        End Function
    </script>

    <body>
        <div style="margin-top:10%;">
            <h1 style="font-family:Segoe UI; color:#AF2B71; text-align: center; margin-top: 100pt">Message Heading</h1>
            <p style="font-family:Segoe UI; text-align: center"><strong/>This is a message which will be displayed to the user. </p>    
        </div>
    </body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As mentioned in the comments, this will have to be added as a project resource and then copied into the output directory.

Explorer has no way of extracting files which have been embedded into an executable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...