저는 웹 브라우저에 표시하고 싶은 웹 페이지가있는 비주얼 스튜디오 프로젝트를 진행하고 있습니다. 현재 나는 모든 필수 html, js 및 css 파일을 복사 한 resources라는 폴더가 있지만 프로젝트에서이 파일을 가리키는 방법을 모른다. 어떤 아이디어? 고맙습니다.비주얼 스튜디오 양식 : Visual Studio 웹 브라우저에서 로컬 index.html 파일을 추가하십시오.
코드 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
string appPath = Assembly.GetEntryAssembly().Location;
string filename = Path.Combine(Path.GetDirectoryName(appPath), "resources\\index.html");
notes.Navigate(filename);
}
}
}
감사합니다.
업데이트
내가 직접 프로젝트에 리소스 폴더의 내용을 붙여 넣기하고, URL에 제시된 여러 옵션을 시도했습니다. 불행히도 아무 것도 작동하지 않고 Visual Studio를 처음 사용하기 때문에 어떤 문제가 있는지 알지 못합니다. 업데이트 된 코드 :
private void Form1_Load(object sender, EventArgs e)
{
//string curDir = Directory.GetCurrentDirectory();
//this.notes.Url = new Uri(String.Format("file:///resources/index.html", curDir));
string applicationDirectory = Path.GetDirectoryName(Application.ExecutablePath);
string myFile = Path.Combine(applicationDirectory, "index.html");
notes.Url = new Uri("file:///" + myFile);
}
[C# WebBrowser에서 로컬 HTML 파일로드] (https://stackoverflow.com/questions/7194851/load-local-html-file-in-ac-sharp)와 중복 될 수 있습니다. -webbrowser) – Sinatr
@Sinatr : 당신이 준 링크에서 해답을 찾았지만 화이트 페이지 만 볼 수 있습니다. 프로젝트에 직접 index.html 파일이 있습니다. 업데이트 된 코드를 확인해 주시겠습니까? 고맙습니다. :-) –
'index.html'의 내용은 무엇입니까 (비워 둘 수 있습니까?)? 'myFile'에 어떤 값이 있고'index.html'이 실제로 위치해 있는지 (Windows 탐색기 경로)? – Sinatr