vb.net - .ToString错误(vb.net)

标签 vb.net compiler-errors

由于某种原因,这对我不起作用,我不确定。我正在尝试为我的Web浏览器设置“设置主页”按钮,这是检查是否设置了页面,然后转到页面的代码:

    Dim HomepageInfo As String
    If IO.File.Exists(Environment.SpecialFolder.ApplicationData & "\Homepage.Info") = True Then
        HomepageInfo = IO.File.ReadAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info")
        WebBrowser1.Url = HomepageInfo.ToString
    Else
        'Create a File with a Default Homepage (www.google.com)
        IO.File.WriteAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info", "www.google.com")
    End If

并且这显示为错误:HomepageInfo.ToString,错误是:“类型'String'的值不能转换为'System.Uri'。”

谢谢你的帮助!

最佳答案

WebBrowser.Url 属性接受uri对象而不是字符串:

Property Value Type: System.Uri A Uri representing the URL of the current document.



因此,您必须使用 Uri 类的实例:

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.



码:
Dim HomepageInfo As String
If IO.File.Exists(Environment.SpecialFolder.ApplicationData & "\Homepage.Info") = True Then
    HomepageInfo = IO.File.ReadAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info")
    WebBrowser1.Url = New Uri(HomepageInfo.ToString)
Else
    'Create a File with a Default Homepage (www.google.com)
    IO.File.WriteAllText(Environment.SpecialFolder.ApplicationData & "\Homepage.Info", "www.google.com")
End If

关于vb.net - .ToString错误(vb.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19682260/

相关文章:

c# - 查找重复单词的值

javascript - 在自动回发下拉列表后刷新 javascript 代码

c - `Cannot find -lmalloc`,错误 : ld returned 1 exit status

创建带有 read( , , ) 错误的 getchar 函数

c# - 常量表达式无法在类型 'UInteger' 中表示

mysql - 我如何使用 LAN 将客户端连接到服务器数据库(mysql)

asp.net - 从字符串 "0.##"到类型 'Integer' 的转换无效

python-3.x - 无法在从源代码构建的Python上编译cx_Freeze

c++ - 重载比较运算符 == C++

java - maven编译失败。无法访问