2012-03-21 14 views
2

htmlをリソースとして埋め込み、C#で外部ブラウザを使用して起動することはできますか?私はプロジェクトのこのhtmlのためだけにWebブラウザコントロールを使いたくありません。これは簡単なヘルプファイルです。可能であれば、リソースとして埋め込みたいので、1つの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); 
関連する問題