3

次の方法で Web ブラウザを開こうとしています。ただし、ブラウザが url / ファイル パスを開くと、フラグメント部分が (「#anchorName」から「%23anchorName」に) 壊れてしまい、処理されていないように見えます。基本的に、ファイルは開きますが、ドキュメント内の適切な場所にジャンプしません。ファイルを開いてフラグメントを処理する方法を知っている人はいますか? これに関するヘルプは大歓迎です。

開くパスの例は、「c:\MyFile.Html#middle」です。

    // calls out to the registry to get the default browser
    private static string GetDefaultBrowserPath()
    {
       string key = @"HTTP\shell\open\command";
       using(RegistryKey registrykey = Registry.ClassesRoot.OpenSubKey(key, false))
       {
          return ((string)registrykey.GetValue(null, null)).Split('"')[1];
       }
    }

    // creates a process and passes the url as an argument to the process
    private static void Navigate(string url)
    {
       Process p = new Process();
       p.StartInfo.FileName = GetDefaultBrowserPath();
       p.StartInfo.Arguments = url;
       p.Start();
    }
4

4 に答える 4

3

あなたに必要なのは:

System.Diagnostics.Process.Start(url);
于 2011-08-25T23:10:35.077 に答える
1

システムに頼って問題を正しく解決してみてください。

    static void Main(string[] args)
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = true;
        p.StartInfo.FileName = "http://stackoverflow.com/questions/tagged/c%23?sort=newest&pagesize=50";
        p.StartInfo.Verb = "Open";
        p.Start();
    }
于 2011-08-25T22:43:15.737 に答える
0

私は C# プログラマーではありませんが、PHP では urlencode を実行します。C# と urlencode で Google 検索を行ったところ、StackOverflow でこのページが表示されました... C# を使用した URL エンコーディング

于 2011-08-25T22:42:24.643 に答える