2
我目前正在開發一個HTML編輯器使用C#,其中有一個預覽選項,但它不編譯...... 這裏是我的代碼:WPF - 不能在WebBrowser控件打開本地機文件
string tempPath = System.IO.Path.GetTempPath();//get TEMP folder location
tempPath += "htmldev\\";
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
tempPath += "current.html";
if(File.Exists(tempPath))
{
File.Delete(tempPath);//delete the old file
}
StreamWriter sr = new StreamWriter(tempPath);
sr.WriteLine(textHtml.Text);//write the HTML code in the temporary file
sr.Close();
previewBrowser.Source = new Uri(tempPath);//When I comment this line my program compiles successfully, and the file is created.
我也嘗試過使用Navigate()方法,但它沒有工作。
我沒有收到任何錯誤或警告。 編輯:如果我嘗試打開一個網站,如google.com它的作品。
它不會編譯,但你沒有得到任何錯誤或警告?什麼? – tnw
previewBrowser的聲明在哪裏? – franssu
什麼部分不起作用?保存文件的顯示文件? – Sheridan