当前位置: 首页>>代码示例>>C#>>正文


C# WebPart.GetType方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.WebParts.WebPart.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# WebPart.GetType方法的具体用法?C# WebPart.GetType怎么用?C# WebPart.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.WebParts.WebPart的用法示例。


在下文中一共展示了WebPart.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProxyWebPart

 protected ProxyWebPart(WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     GenericWebPart part = webPart as GenericWebPart;
     if (part != null)
     {
         Type type;
         Control childControl = part.ChildControl;
         if (childControl == null)
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPart");
         }
         this._originalID = childControl.ID;
         if (string.IsNullOrEmpty(this._originalID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ChildControl.ID" }), "webPart");
         }
         UserControl control2 = childControl as UserControl;
         if (control2 != null)
         {
             type = typeof(UserControl);
             this._originalPath = control2.AppRelativeVirtualPath;
         }
         else
         {
             type = childControl.GetType();
         }
         this._originalTypeName = WebPartUtil.SerializeType(type);
         this._genericWebPartID = part.ID;
         if (string.IsNullOrEmpty(this._genericWebPartID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart");
         }
         this.ID = this._genericWebPartID;
     }
     else
     {
         this._originalID = webPart.ID;
         if (string.IsNullOrEmpty(this._originalID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart");
         }
         this._originalTypeName = WebPartUtil.SerializeType(webPart.GetType());
         this.ID = this._originalID;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:49,代码来源:ProxyWebPart.cs

示例2: ProxyWebPart

        protected ProxyWebPart(WebPart webPart) {
            if (webPart == null) {
                throw new ArgumentNullException("webPart");
            }

            GenericWebPart genericWebPart = webPart as GenericWebPart;
            if (genericWebPart != null) {
                Control childControl = genericWebPart.ChildControl;
                if (childControl == null) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPart");
                }

                _originalID = childControl.ID;
                if (String.IsNullOrEmpty(_originalID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ChildControl.ID"), "webPart");
                }

                Type originalType;
                UserControl childUserControl = childControl as UserControl;
                if (childUserControl != null) {
                    originalType = typeof(UserControl);
                    _originalPath = childUserControl.AppRelativeVirtualPath;
                }
                else {
                    originalType = childControl.GetType();
                }
                _originalTypeName = WebPartUtil.SerializeType(originalType);
                _genericWebPartID = genericWebPart.ID;
                if (String.IsNullOrEmpty(_genericWebPartID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart");
                }
                ID = _genericWebPartID;
            }
            else {
                _originalID = webPart.ID;
                if (String.IsNullOrEmpty(_originalID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart");
                }
                _originalTypeName = WebPartUtil.SerializeType(webPart.GetType());
                ID = _originalID;
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:42,代码来源:ProxyWebPart.cs

示例3: WebPartTracker

        public WebPartTracker(WebPart webPart, ProviderConnectionPoint providerConnectionPoint) {
            if (webPart == null) {
                throw new ArgumentNullException("webPart");
            }

            if (providerConnectionPoint == null) {
                throw new ArgumentNullException("providerConnectionPoint");
            }

            if (providerConnectionPoint.ControlType != webPart.GetType()) {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_InvalidConnectionPoint), "providerConnectionPoint");
            }

            _webPart = webPart;
            _providerConnectionPoint = providerConnectionPoint;

            if (++Count > 1) {
                webPart.SetConnectErrorMessage(SR.GetString(SR.WebPartTracker_CircularConnection, _providerConnectionPoint.DisplayName));
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:20,代码来源:WebPartTracker.cs

示例4: WebPartTracker

 public WebPartTracker(WebPart webPart, ProviderConnectionPoint providerConnectionPoint)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     if (providerConnectionPoint == null)
     {
         throw new ArgumentNullException("providerConnectionPoint");
     }
     if (providerConnectionPoint.ControlType != webPart.GetType())
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_InvalidConnectionPoint"), "providerConnectionPoint");
     }
     this._webPart = webPart;
     this._providerConnectionPoint = providerConnectionPoint;
     if (++this.Count > 1)
     {
         webPart.SetConnectErrorMessage(System.Web.SR.GetString("WebPartTracker_CircularConnection", new object[] { this._providerConnectionPoint.DisplayName }));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:WebPartTracker.cs

示例5: IsAuthorized

 public bool IsAuthorized(WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     string authorizationFilter = webPart.AuthorizationFilter;
     if (!string.IsNullOrEmpty(webPart.ID) && this.Personalization.IsEnabled)
     {
         string str3 = this.Personalization.GetAuthorizationFilter(webPart.ID);
         if (str3 != null)
         {
             authorizationFilter = str3;
         }
     }
     GenericWebPart part = webPart as GenericWebPart;
     if (part == null)
     {
         return this.IsAuthorized(webPart.GetType(), null, authorizationFilter, webPart.IsShared);
     }
     Type type = null;
     string path = null;
     Control childControl = part.ChildControl;
     UserControl control2 = childControl as UserControl;
     if (control2 != null)
     {
         type = typeof(UserControl);
         path = control2.AppRelativeVirtualPath;
     }
     else
     {
         type = childControl.GetType();
     }
     return this.IsAuthorized(type, path, authorizationFilter, webPart.IsShared);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:WebPartManager.cs

示例6: CopyWebPart

 protected virtual WebPart CopyWebPart(WebPart webPart)
 {
     WebPart part;
     GenericWebPart part2 = webPart as GenericWebPart;
     if (part2 != null)
     {
         Control childControl = part2.ChildControl;
         this.VerifyType(childControl);
         Type type = childControl.GetType();
         Control control = (Control) this.Internals.CreateObjectFromType(type);
         control.ID = this.CreateDynamicWebPartID(type);
         part = this.CreateWebPart(control);
     }
     else
     {
         this.VerifyType(webPart);
         part = (WebPart) this.Internals.CreateObjectFromType(webPart.GetType());
     }
     part.ID = this.CreateDynamicWebPartID(webPart.GetType());
     return part;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:WebPartManager.cs

示例7: ProcessWebpartCustomProperties

        protected virtual void ProcessWebpartCustomProperties(WebPart instance, WebPartDefinition definition)
        {
            if (definition.Properties != null && definition.Properties.Count > 0)
            {
                var wpType = instance.GetType();

                foreach (var prop in definition.Properties)
                {
                    var isCdata = prop.IsCData.HasValue && prop.IsCData.Value;

                    if (ReflectionUtils.HasProperty(instance, prop.Name))
                    {
                        var wpProp = wpType.GetProperty(prop.Name);
                        var wpPropType = wpProp.PropertyType;

                        var targetValue = Convert.ChangeType(prop.Value, wpPropType);

                        wpProp.SetValue(instance, targetValue, null);
                    }
                }
            }
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:22,代码来源:WebPartModelHandler.cs

示例8: CopyPersonalizationState

        // Extracts the personalization state from webPartA, and applies it to webPartB.
        // Assumes that webPartA and webPartB are the same type.  If the WebParts are GenericWebParts,
        // then copies the personalization state from the ChildControl of webPartA to the
        // ChildControl of webPartB.
        protected internal virtual void CopyPersonalizationState(WebPart webPartA, WebPart webPartB) {
            if (webPartA == null) {
                throw new ArgumentNullException("webPartA");
            }
            if (webPartB == null) {
                throw new ArgumentNullException("webPartB");
            }
            if (webPartA.GetType() != webPartB.GetType()) {
                throw new ArgumentException(SR.GetString(SR.WebPartPersonalization_SameType, "webPartA", "webPartB"));
            }

            CopyPersonalizationState((Control)webPartA, (Control)webPartB);

            GenericWebPart genericWebPartA = webPartA as GenericWebPart;
            GenericWebPart genericWebPartB = webPartB as GenericWebPart;
            // Assert that the GenericWebParts are either both null or both non-null
            Debug.Assert((genericWebPartA == null) == (genericWebPartB == null));
            if (genericWebPartA != null && genericWebPartB != null) {
                Control childControlA = genericWebPartA.ChildControl;
                Control childControlB = genericWebPartB.ChildControl;

                if (childControlA == null) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPartA");
                }
                if (childControlB == null) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPartB");
                }
                if (childControlA.GetType() != childControlB.GetType()) {
                    throw new ArgumentException(SR.GetString(SR.WebPartPersonalization_SameType, "webPartA.ChildControl", "webPartB.ChildControl"));
                }

                CopyPersonalizationState(childControlA, childControlB);
            }

            // IPersonalizable.IsDirty should always be false on the new WebPart, since the only data
            // on the new WebPart was loaded via personalization, which should not cause the control
            // to be dirty.  However, we want to save the IPersonalizable data on this request, so
            // we call SetDirty() to force the IPersonalizable data to be saved.
            SetDirty(webPartB);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:44,代码来源:WebPartPersonalization.cs

示例9: IsAuthorized

        public bool IsAuthorized(WebPart webPart) {
            if (webPart == null) {
                throw new ArgumentNullException("webPart");
            }

            // Do not check that Controls.Contains(webPart), since this will be called on a WebPart
            // before it is added to the Controls collection.

            // Calculate authorizationFilter from property value and personalization data
            string authorizationFilter = webPart.AuthorizationFilter;

            // webPart.ID will be null for imported WebParts.  Also, a user may want to call
            // this method on a WebPart before it has an ID.
            string webPartID = webPart.ID;
            if (!String.IsNullOrEmpty(webPartID) && Personalization.IsEnabled) {
                string personalizedAuthorizationFilter = Personalization.GetAuthorizationFilter(webPart.ID);
                if (personalizedAuthorizationFilter != null) {
                    authorizationFilter = personalizedAuthorizationFilter;
                }
            }

            GenericWebPart genericWebPart = webPart as GenericWebPart;
            if (genericWebPart != null) {
                Type childType = null;
                string childPath = null;

                Control childControl = genericWebPart.ChildControl;
                UserControl childUserControl = childControl as UserControl;
                if (childUserControl != null) {
                    childType = typeof(UserControl);
                    childPath = childUserControl.AppRelativeVirtualPath;
                }
                else {
                    childType = childControl.GetType();
                }

                // Only authorize the type/path of the child control
                // Don't need to authorize the GenericWebPart as well
                return IsAuthorized(childType, childPath, authorizationFilter, webPart.IsShared);
            }
            else {
                return IsAuthorized(webPart.GetType(), null, authorizationFilter, webPart.IsShared);
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:44,代码来源:WebPartManager.cs

示例10: CopyWebPart

        // Returns a copy of the WebPart, with all the properties reset to their default value.
        // If the WebPart is a GenericWebPart, returns a copy of the GenericWebPart and a copy of the
        // ChildControl inside the GenericWebPart.  The ID of the new WebPart and ChildControl should
        // be set to a value obtained from CreateDynamicWebPartID.
        // Virtual because a derived WebPartManager will deserialize a WebPart from XML in this method.
        protected virtual WebPart CopyWebPart(WebPart webPart) {
            WebPart newWebPart;

            GenericWebPart genericWebPart = webPart as GenericWebPart;
            if (genericWebPart != null) {
                Control childControl = genericWebPart.ChildControl;
                VerifyType(childControl);
                Type childControlType = childControl.GetType();
                Control newChildControl = (Control)Internals.CreateObjectFromType(childControlType);
                newChildControl.ID = CreateDynamicWebPartID(childControlType);

                newWebPart = CreateWebPart(newChildControl);
            }
            else {
                VerifyType(webPart);
                newWebPart = (WebPart)Internals.CreateObjectFromType(webPart.GetType());
            }

            newWebPart.ID = CreateDynamicWebPartID(webPart.GetType());

            return newWebPart;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:27,代码来源:WebPartManager.cs

示例11: SetWebPart

        internal static void SetWebPart(WebPart sourceWebPart, string targetUrl, string zone, int? zoneIndex, bool publish, bool test)
        {
            if (sourceWebPart.IsClosed)
            {
                sourceWebPart.Dispose();
                throw new Exception("The source web part is closed and cannot be copied.");
            }

            int zoneIndex1 = sourceWebPart.ZoneIndex;
            if (zoneIndex.HasValue)
                zoneIndex1 = zoneIndex.Value;
            Guid storageKey = Guid.NewGuid();
            string id = StorageKeyToID(storageKey);

            using (SPSite site = new SPSite(targetUrl))
            using (SPWeb web = site.OpenWeb()) // The url contains a filename so AllWebs[] will not work unless we want to try and parse which we don't
            {
                bool cleanupContext = false;
                try
                {
                    if (HttpContext.Current == null)
                    {
                        cleanupContext = true;
                        HttpRequest httpRequest = new HttpRequest("", web.Url, "");
                        HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new StringWriter()));
                        SPControl.SetContextWeb(HttpContext.Current, web);
                    }

                    SPFile file = web.GetFile(targetUrl);

                    // file.Item will throw "The object specified does not belong to a list." if the url passed
                    // does not correspond to a file in a list.

                    bool checkIn = false;
                    if (file.InDocumentLibrary && !test)
                    {
                        if (!Utilities.IsCheckedOut(file.Item) || !Utilities.IsCheckedOutByCurrentUser(file.Item))
                        {
                            file.CheckOut();
                            checkIn = true;
                            // If it's checked out by another user then this will throw an informative exception so let it do so.
                        }
                    }

                    SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
                    try
                    {
                        string wpTitle = sourceWebPart.Title;
                        if (string.IsNullOrEmpty(wpTitle)) wpTitle = sourceWebPart.DisplayTitle;

                        Logger.Write("Copying web part \"{0}\"...", wpTitle);
                        WebPart newWebPart = (WebPart)Activator.CreateInstance(sourceWebPart.GetType());
                        if (SPCmdletReplaceWebPartType.SetProperties(sourceWebPart, newWebPart, null))
                        {
                            Logger.WriteWarning("An error was encountered setting web part properties so try one more time in case the error is the result of a sequencing issue.");
                            if (SPCmdletReplaceWebPartType.SetProperties(sourceWebPart, newWebPart, null))
                            {
                                Logger.WriteWarning("Unable to set all properties for web part.");
                            }
                        }

                        try
                        {
                            if (!test)
                            {
                                newWebPart.ID = id;

                                manager.AddWebPart(newWebPart, zone, zoneIndex1);
                            }
                        }
                        catch (Exception)
                        {
                            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

                            // We've not already added the web part so use the web service to do this.
                            using (WebPartPagesWebService.WebPartPagesWebService svc = new WebPartPagesWebService.WebPartPagesWebService())
                            {
                                // We failed adding via the OM so try the web service as a fall back.
                                svc.Url = manager.Web.Url + "/_vti_bin/WebPartPages.asmx";
                                svc.Credentials = CredentialCache.DefaultCredentials;

                                try
                                {
                                    // Add the web part to the web service.  We use a web service because many
                                    // web parts require the SPContext.Current variables to be set which are
                                    // not set when run from a command line.
                                    StringBuilder sb = new StringBuilder();
                                    XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(sb));
                                    xmlWriter.Formatting = Formatting.Indented;
                                    manager.ExportWebPart(newWebPart, xmlWriter);
                                    xmlWriter.Flush();

                                    svc.AddWebPartToZone(targetUrl, sb.ToString(), Storage.Shared, zone, zoneIndex1);

                                }
                                catch (SoapException ex)
                                {
                                    throw new Exception(ex.Detail.OuterXml);
                                }
                            }
//.........这里部分代码省略.........
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:101,代码来源:SPCmdletCopyWebPart.cs

示例12: ExportWebPart

 public override void ExportWebPart(WebPart webPart, XmlWriter writer)
 {
     if (webPart is IConfigurableWebPart)
     {
         writer.WriteStartElement("webPart");
         writer.WriteAttributeString("type", SerializationServices.ShortAssemblyQualifiedName(webPart.GetType().AssemblyQualifiedName));
         IConfiguration config = (webPart as IConfigurableWebPart).Configuration;
         SerializationServices.Serialize(config, writer);
         writer.WriteEndElement();
     }
     else
     {
         base.ExportWebPart(webPart, writer);
     }
 }
开发者ID:t1b1c,项目名称:lwas,代码行数:15,代码来源:Manager.cs

示例13: SetWebPartProperties

        /// <summary>
        /// Sets the web part properties.
        /// </summary>
        /// <param name="xWp">The x wp.</param>
        /// <param name="properties">The properties.</param>
        private static void SetWebPartProperties(WebPart xWp, Hashtable properties)
        {
            if (properties == null)
                return;

            foreach (string prop in properties.Keys)
            {
                try
                {
                    object val = properties[prop];
                    if (xWp is Microsoft.SharePoint.WebPartPages.WebPart)
                    {
                        if (prop == "Width")
                        {
                            ((Microsoft.SharePoint.WebPartPages.WebPart)xWp).Width = val.ToString();
                            return;
                        }
                        if (prop == "Height")
                        {
                            ((Microsoft.SharePoint.WebPartPages.WebPart)xWp).Height = val.ToString();
                            return;
                        }
                    }
                    PropertyInfo propInfo = xWp.GetType().GetProperty(prop);
                    if (propInfo == null)
                        throw new SPException(string.Format("Unable to set property '{0}'.  The property could not be found.", prop));

                    val = Convert.ChangeType(val, propInfo.PropertyType);
                    if (val == null)
                        throw new SPException(string.Format("Unable to convert '{0}' to type '{1}'", properties[prop], propInfo.PropertyType));

            #if MOSS
                    if (xWp is KPIListWebPart && prop == "TitleUrl")
                    {
                        if (val.ToString().Contains("://"))
                            val = Utilities.GetServerRelUrlFromFullUrl((string)val);
                    }
                    if (xWp is KPIListWebPart && prop == "ListURL")
                    {
                        if (val.ToString().Contains("://"))
                            val = Utilities.GetServerRelUrlFromFullUrl((string)val);

                        Utilities.SetFieldValue(xWp, typeof(KPIListWebPart), "listUrl", val);
                        Utilities.SetFieldValue(xWp, typeof(KPIListWebPart), "spList", null);
                        continue;
                    }
            #endif

                    propInfo.SetValue(xWp, val, null);
                }
                catch (Exception ex)
                {
                    throw new SPException(string.Format("Error setting property value {0} to {1}:\r\n{2}", prop, properties[prop], Utilities.FormatException(ex)));
                }
            }
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:61,代码来源:SetWebPartState.cs

示例14: CopyPersonalizationState

 protected internal virtual void CopyPersonalizationState(WebPart webPartA, WebPart webPartB)
 {
     if (webPartA == null)
     {
         throw new ArgumentNullException("webPartA");
     }
     if (webPartB == null)
     {
         throw new ArgumentNullException("webPartB");
     }
     if (webPartA.GetType() != webPartB.GetType())
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartPersonalization_SameType", new object[] { "webPartA", "webPartB" }));
     }
     this.CopyPersonalizationState((Control) webPartA, (Control) webPartB);
     GenericWebPart part = webPartA as GenericWebPart;
     GenericWebPart part2 = webPartB as GenericWebPart;
     if ((part != null) && (part2 != null))
     {
         Control childControl = part.ChildControl;
         Control controlB = part2.ChildControl;
         if (childControl == null)
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPartA");
         }
         if (controlB == null)
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPartB");
         }
         if (childControl.GetType() != controlB.GetType())
         {
             throw new ArgumentException(System.Web.SR.GetString("WebPartPersonalization_SameType", new object[] { "webPartA.ChildControl", "webPartB.ChildControl" }));
         }
         this.CopyPersonalizationState(childControl, controlB);
     }
     this.SetDirty(webPartB);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:WebPartPersonalization.cs


注:本文中的System.Web.UI.WebControls.WebParts.WebPart.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。