0

저는 웹 브라우저에 표시하고 싶은 웹 페이지가있는 비주얼 스튜디오 프로젝트를 진행하고 있습니다. 현재 나는 모든 필수 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); 
     } 
+2

[C# WebBrowser에서 로컬 HTML 파일로드] (https://stackoverflow.com/questions/7194851/load-local-html-file-in-ac-sharp)와 중복 될 수 있습니다. -webbrowser) – Sinatr

+0

@Sinatr : 당신이 준 링크에서 해답을 찾았지만 화이트 페이지 만 볼 수 있습니다. 프로젝트에 직접 index.html 파일이 있습니다. 업데이트 된 코드를 확인해 주시겠습니까? 고맙습니다. :-) –

+0

'index.html'의 내용은 무엇입니까 (비워 둘 수 있습니까?)? 'myFile'에 어떤 값이 있고'index.html'이 실제로 위치해 있는지 (Windows 탐색기 경로)? – Sinatr

답변

0

here (생산 코드를합니다 논의 된 것 같은 데스크톱 응용 프로그램에서 (윈폼 응용 프로그램의 예 : "브라우저의 쇼"버튼), 당신은 System.Diagnostics.Process.Start("http://localhost:42")을 사용할 수를 브라우저에서 링크를 열려면 일부 비 로컬 호스트 링크가 있음).

그 전에 host your website on local IIS을 입력하고 포트 (예 : 42)를 지정해야합니다.

반면에 웹 응용 프로그램 (C# 백 엔드 코드 사용)을 만들려면 다른 형식의 프로젝트 (WinForms 아님)를 사용해야합니다. ASP.NET MVC

편집 : System.Diagnostics.Process.Start도 로컬 파일과 함께 작동합니다. System.Diagnostics.Process.Start(@"C:\Sites\index.html");

EDIT 2 : application directory과 같이 사용할 수도 있습니다. System.Diagnostics.Process.Start(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"site\index.html")) 앱의 경로를 상대적으로 유지하기 위해

+0

우리는 서버없이 인터넷없이 exe가 실행될 때 실행할 수있는 패키지 응용 프로그램을 만드는 데 더욱 관심이 있습니다. 그래서 내가 처음에는 Visual Studio를 사용하고, 그렇지 않으면 다른 플랫폼에서도 쉽게 할 수 있습니다. 어떤 생각인지 내가 뭘 잘못 했니? 고맙습니다. –

+0

어쨌든 파일을 프로젝트 안에 넣고 상대 경로로 작업 할 수 있습니까? 우리는 나중에 그것을 포장하기 때문에 절대적이지 않습니다. 고맙습니다. –

+0

데스크톱 애플리케이션에서 정적 페이지 (예 : index.html)를 호출 하시겠습니까? 그렇다면 편집 후에 설명 된 것처럼 정적 페이지를 열 수 있습니다. 정적 페이지는 응용 프로그램 폴더에 저장 될 수 있으며 상대 경로에 의해 호출됩니다. –