<Bindable(True), Category("Behaviour"), DefaultValue("Links.xml"), Description("The name of the XML file to use")> _
        Public Overridable Property XMLFile() As String
            Get
                Return _XMLFile
            End Get
            Set(ByVal Value As String)
                If TypeOf Value Is String Then _XMLFile = Value
                If Not New FileInfo(context.Server.MapPath(_XMLFile)).Exists Then
                    Throw New ApplicationException(String.Format("The XML '{0}' cannot be found", _XMLFile))
                End If
            End Set
        End Property

解决方案 »

  1.   

    [Bindable(true), Category("Behaviour"), DefaultValue("Links.xml"), Description("The name of the XML file to use")] 
    public virtual string XMLFile { 
     get { 
       return _XMLFile; 
     } 
     set { 
       if (Value is string) { 
         _XMLFile = Value; 
       } 
       if (!new FileInfo(context.Server.MapPath(_XMLFile)).Exists) { 
         throw new ApplicationException(string.Format("The XML '{0}' cannot be found", _XMLFile)); 
       } 
     } 
    }
      

  2.   

    给定表达式始终为所提供的(“string”)类型这样的代码是不能过的,自己试就知道了
      

  3.   

    if (Value is string) 
    给定表达式始终为所提供的(“string”)类型(context.Server.MapPath(_XMLFile)).Exists)
    找不到类型或命名空间名称“context”(是否缺少 using 指令或程序集引用?)
      

  4.   

    以下是上面vb.net代码的定义
    部分
    Option Explicit On 
    Option Strict OnImports System.ComponentModel
    Imports System.Web.UI
    Imports System.Xml
    Imports System.IO
    Imports SystemNamespace Lyquidity.UtilityLibrary.WebControls    <DefaultProperty("Text"), ToolboxData("<{0}:WebPartsControl runat=server></{0}:WebPartsControl>")> _
        Public Class WebPartsControl
            Inherits System.Web.UI.WebControls.WebControl        ' Property variables
            Private _XMLFile As String = "Links.xml"
            Private _DefaultPage As String = "http://www.google.com"
            Private _HTMLSubFolder As String = "HTML"         ' Location of the folder containing the Web Part snippets (relative to page on which control is used)
            Private _LinkFrame As String = "_Parent"        ' XML variables use to retreve information from the l
            Private _FrameLinks As XmlNodeList
            Private _PopupLinks As XmlNodeList
            Private _doc As XmlDocument = New XmlDocument()        ' Webpart snippet variables
            Private _FrameLink As String
            Private _PopupLink As String
            Private _LinkGroup As String
            Private _WebPart As String        ' XML file tag names
            Private ReadOnly _LinksMemberTag As String = "/link"
            Private ReadOnly _PopupLinkGroupsMemberTag As String = "/group"        Private _FrameLinksXPathQuery As String = "/links/framelinks"
            Private _PopupLinksXPathQuery As String = "/links/popuplinks"        Private _FrameLinkMembersXPathQuery As String = _FrameLinksXPathQuery & _LinksMemberTag
            Private _PopupLinkGroupsXPathQuery As String = _PopupLinksXPathQuery & _PopupLinkGroupsMemberTag
      

  5.   

    [Bindable(true), Category("Behaviour"), DefaultValue("Links.xml"), Description("The name of the XML file to use")] 
    public virtual string XMLFile { 
     get { 
       return _XMLFile; 
     } 
     set { 
       if (typeof(Value) is string) { //原来这里没有获取Value运行时的类型所以
         _XMLFile = Value; 
       } 
       if (!new FileInfo(context.Server.MapPath(_XMLFile)).Exists) { 
         throw new ApplicationException(string.Format("The XML '{0}' cannot be found", _XMLFile)); 
       } 
     } 
    }
      

  6.   

    对vb.net不是很熟悉,翻译成C#应该就是这样的吧:[Bindable(true),Category("Behavior"),DefaultValue("Links.xml"),Description("The name of the XML file to use")]public virtual string XMLFile
    {
    get{
    return _XMLFile;
    }
    set
    {
    _XMLFile=value;
    if(!File.Exists(context.Server.MapPath(_XMLFile)))
    throw new ApplicationException(String.Format("The XML '{0}' cannot be found", _XMLFile));
    }
    }