Cообщество разработчиков на платформе Microsoft > Форумы > SharePoint - Design and Customization > error "object reference not set to an instance of an object" when open custom webpart in sharepoint Designer
Задайте вопросЗадайте вопрос
 

Вопросerror "object reference not set to an instance of an object" when open custom webpart in sharepoint Designer

Все ответы

  • 2 июля 2009 г. 14:55Mike Walsh MVPMVP, МодераторМедали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    spd questions go to Design/customization

    Moving this


    WSS FAQ sites: http://wssv2faq.mindsharp.com and http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 / MOSS 2007 Books (including foreign language) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
  • 2 июля 2009 г. 15:11ccvalenc Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    I´m not sure, but if you use the context maybe on designer context be null and because of it, give you this error.

    What kind of webpart or operations do? Can you put some code?
    Microsoft MCP 6608628
  • 3 июля 2009 г. 11:28AshishKumarVerma Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    We have created custom webpart which is inherited from Microsoft System.web.ui.webcontrols.webparts.Webpart class.
    like this

    public class CustomWebPart01 : WebPart
    {
    implementation code
    }

     I have also remove the use of SPcontext to pick site url and start picking site URL from web.config fileas using appsettings, but still the same error has woccurs.

  • 3 июля 2009 г. 14:16Dave Hunter Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    Can you edit an out of the box webpart with SPD?  Just trying to find out if its a code issue with your custom webpart or a SPD issue?  If you can edit a standard webpart, can you post your code for your custom webparts?

    Dave
    My SharePoint Blog - http://www.davehunter.co.uk/blog
  • 8 июля 2009 г. 13:47AshishKumarVerma Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    Hi

    I have tried a lot and come to know that when I put my custom web part dll into bin directory of the the web site and then add custom web part to the web page of the site and open the page (containing custom web part) in sharepoint designer is displaying fine.
    but when i put same dll into GAC(C:\windows\assembly) and add custom web part to the web page of the site and open it in the sharepoint designer then error "object reference not set to an instance of an object" occurs.
    Means the same dll is working fine from bin directory of the site.

    But the requirement is to put the dll in the GAC(C:\windows\assembly), so please suggest the solution.
    code for the custom web part dll is as follows

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using System.Web;
    using System.Net;
    namespace Test
    {
        public class CustomWebPart01 : WebPart
        {
            private TeamwareServiceInfo twSvcInfo;
            private string _strTwSrvUrl = "";
            //Default Constructor
            public CustomWebPart01()
            {
                Settings twSettings = (Settings)HttpContext.Current.Application[Def.TeamwareSettings];
                twSvcInfo = twSettings.DefaultTwSvcInfo;
                _strTwSrvUrl = twSvcInfo.ToString();

            }
            private string _strDefaultUrl = "";
            private string _strWidth = "100";
            private string _strHeight = "100";

            //Custom property to display URL in property sheet.
            [WebBrowsable(true),
            WebDescription("Displays a custom message"),
            WebDisplayName("To specify a link, type a URL or path."),
            Personalizable(PersonalizationScope.User)]

            public string DisplayMessage
            {
                get
                {
                    return _strDefaultUrl;
                }
                set
                {
                    _strDefaultUrl = value;
                }
            }

            //Custom property for width in the property sheet.
            [WebBrowsable(true),
            WebDescription("Display IFrame width in %"),
            WebDisplayName("Enter IFrame Width[%] "),
            Personalizable(PersonalizationScope.User)]

            public string FrameWidth
            {
                get
                {
                    return _strWidth;
                }
                set
                {
                    _strWidth = value;
                }
            }

            //Custom property to display height in the property sheet.
            [WebBrowsable(true),
            WebDescription("Display IFrame Height in %"),
            WebDisplayName("Enter IFrame Height[%] "),
            Personalizable(PersonalizationScope.User)]

            public string FrameHeight
            {
                get
                {
                    return _strHeight;
                }
                set
                {
                    _strHeight = value;
                }
            }

            //overriding the systems default CreateChildControls method
            protected override void CreateChildControls()
            {
                string _strRequestUrl = "";

                //Code for picking default setting
                if ((_strDefaultUrl == "") && (_strTwSrvUrl != ""))
                {
                    _strDefaultUrl = _strTwSrvUrl;
                }
                else if (_strTwSrvUrl != "")
                {
                    int nPos = _strDefaultUrl.IndexOf("//");
                    string _strTemp = "";
                    int nPos1 = -1;
                    if (nPos != -1)
                    {
                        nPos1 = _strDefaultUrl.IndexOf('/', nPos + 2);
                        if (nPos1 != -1)
                        {
                            _strTemp = _strDefaultUrl.Substring(nPos1 + 1);
                        }
                    }
                    _strDefaultUrl = _strTwSrvUrl + _strTemp;
                }
                if (_strDefaultUrl != "")
                {
                    int nPos = _strDefaultUrl.IndexOf("//");
                    int nPos1 = -1;
                    if (nPos != -1)
                    {
                        nPos1 = _strDefaultUrl.IndexOf('/', nPos + 2);
                        if (nPos1 != -1)
                        {
                            _strRequestUrl = _strDefaultUrl.Substring(0, nPos1);
                        }
                        else
                        {
                            _strRequestUrl = _strDefaultUrl;
                        }
                    }
                }
                base.CreateChildControls();
                HtmlGenericControl twoFrame = new HtmlGenericControl("iframe");
                twoFrame.ID = "IEFrame";

                //Code to check that temaware server is running or not
                //Commented code is for proxy settings.
                try
                {
                    HttpWebResponse _httpWbResponse = null;
                    HttpWebRequest _httpWbRequest = null;
                    if (_strRequestUrl != "")
                    {
                        _httpWbRequest = (HttpWebRequest)WebRequest.Create(_strRequestUrl);
                        _httpWbRequest.ServicePoint.ConnectionLimit = 50;
                        _httpWbRequest.Timeout = 200000;
                        _httpWbResponse = (HttpWebResponse)_httpWbRequest.GetResponse();
                        if ((_httpWbResponse.StatusCode == HttpStatusCode.OK))
                        {
                            twoFrame.Attributes.Add("src", _strDefaultUrl);
                        }
                    }

                }
                catch (Exception)
                {
                    twoFrame.Attributes.Add("src", "/_LAYOUTS/ErrorMessages.aspx");
                }
                //End
                twoFrame.Attributes.Add("width", _strWidth + "%");
                twoFrame.Attributes.Add("height", _strHeight + "%");
                twoFrame.Attributes.Add("frameborder", "0");
                twoFrame.Attributes.Add("border", "0");
                this.Controls.Add(twoFrame);
            }
           
        }
    }


    Thanks
    Ashish