![](/img/trans.png)
[英]deserialize json in c# from the web in a c# console app
[英]Opening a web page from a C# console app
我是C#编程的新手,所以请原谅。 我只是尝试了上一个问题中提出的解决方案,但是没有用。 顺便说一句,我仍然需要帮助。 我正在尝试使用C#编写一个简单的consolle应用程序,以打开一个网页,即http://www.libero.it 。 这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
class OpenWeb {
static void Main(string[] args) {
var prs = new ProcessStartInfo("chrome.exe");
prs.Arguments = "http://www.libero.it";
// Process.Start(prs);
try
{
Process.Start(prs);
}
catch (System.ComponentModel.Win32Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
我不明白为什么我的代码无法正常工作,总会有一种误解,没有try-catch的情况如下:
Unhandled Exception: System.ComponentModel.Win32Exception: The specified file
could not be found
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OpenWeb.Main(String[] args) in C:\Users\p3rtp\myProve\Prove.cs:line 12
我使用Windows 7x64和.Net核心SDK 2.1.301和MS Visual Studio Code 1.24.1。
我一直在使用此行来启动默认浏览器:
System.Diagnostics.Process.Start("http://www.google.com");
代码非常简单,如下所示:
using System
using System.Collections.Generic
using System.Text
using System.Diagnostics
namespace example
{
class examp
{
static void Main(string[] args)
{
Process.Start("http://www.google.com");
}
}
}
好的,我找到了正确的答案:
var prs = new ProcessStartInfo(@"C:\Program Files
(x86)\Google\Chrome\Application\chrome.exe");
问题不在于路径,而在于应用程序或文件夹中:只是在chrome的完整路径之前带有"@"
的引号,我终于设法解决了这个问题。 仍然感谢所有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.