2012-03-21 2 views
2

html을 리소스로 포함시키고 C#에서 외부 브라우저를 사용하여 시작할 수 있습니까? 프로젝트에서이 HTML에 대한 웹 브라우저 컨트롤을 사용하고 싶지 않습니다. 그것은 간단한 도움말 파일입니다. 가능한 한 리소스로 포함하고 싶습니다. 그래서 처리 할 단일 EXE를 가질 수 있습니다.C#에서 외부 브라우저에 포함 된 html을 여는

감사

이 같은
+0

왜 웹 브라우저 컨트롤을 사용하지 않으시겠습니까? 파일을 외부로 보내지 않으려면 가장 명백한 해결책으로 보입니다. – KingCronus

+0

WinForms 또는 WPF? 이 고양이를 껍질을 벗기는 2 가지 방법이 있기 때문입니다. – code4life

+0

@ Adam. 그냥 더 많은 코드를 추가하고 싶습니다. 더 간단한 방법이 있습니다. – Murlex

답변

4

드래그하여 리소스 탭에 자원 html 파일을 드롭 :

var txt = Properties.Resources.sample; 
var fileName = Path.ChangeExtension(Path.GetTempFileName(), ".html"); 

var fs = File.CreateText(fileName); 
fs.Write(txt); 
fs.Flush(); 
fs.Close(); 

Process.Start(fileName); 

입니다 :

Resources View

그런 다음 다음 코드를 사용하여 그것에 대해 ...

+0

입니다.이 대답을 단순함으로 올바른 것으로 표시하고 있습니다 ... 감사합니다! – Murlex

+0

단순한 것이 가장 좋습니다 ..'Properties'는 멋진 검은 색 상자 안에 모든 뒤의 코드를 포함합니다. lol – code4life

+0

'Path.Combine()'을'Path.ChangeExtension()'으로 변경하십시오. –

1
public void ExtractFileFromResources(String filename, String location) 
     { 
      // Assembly assembly = Assembly.GetExecutingAssembly(); 
      System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); 
         Stream resFilestream = a.GetManifestResourceStream(filename); 
      if (resFilestream != null) 
      { 
       BinaryReader br = new BinaryReader(resFilestream); 
       FileStream fs = new FileStream(location, FileMode.Create); 
       BinaryWriter bw = new BinaryWriter(fs); 
       byte[] ba = new byte[resFilestream.Length]; 
       resFilestream.Read(ba, 0, ba.Length); 
       bw.Write(ba); 
      br.Close(); 
      bw.Close(); 
      resFilestream.Close(); 
     } 

    } 

string path = Path.Combine(System.IO.Path.GetTempPath() + "\file.html"); 

ExtractFileFromResources("file.html", path); 


Process.Start(path); 
관련 문제