.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Error occured when using SPWeb or SPSite in webpart

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :SharePoint
 

I am creating a custom webpart, in which I have a label control. This label will display the current site URL and here is the code

protected override void CreateChildControls()
        {
            base.CreateChildControls();
            SPWeb wb = SPContext.Current.Web;
            string baseURL = wb.Url.ToString();
            Label lblTitle = new Label();
            lblTitle.Text = baseURL.ToString();
        }

But when I try to use SPWeb or SPSite within CreateChildControl method, I am getting an unexpected error occurred message. Also I have used "using Microsoft.SharePoint;" too.

If suppose I comment those two line my web part is displaying the properly. As below

protected override void CreateChildControls()
        {
            base.CreateChildControls();
            //SPWeb wb = SPContext.Current.W


View Complete Post


More Related Resource Links

Error opening site using SPSite and SPWeb instances using VS 2010, Win Server 2008 R2

  

Hi I am trying to open my site using SPSite and SPWeb instances and getting an error message as below-

The Web application at http://url could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

  CODE is -

     SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    SPSite siteCOll = new SPSite(siteURL);

                    SPWeb oWeb = siteCOll.OpenWeb("url");

-----

----

I can access site using browser perfectly.

I am running VS as administrator.

I have done permission checking aswell.

 

please help!

Thanks

 

 

 


Activation error occured while trying to get instance of type Database, key "DBName"

  

Im using Enterprise library 5.0
I have a scenario, where I have to access two different databases in my application.

Basically this application is a webservice,delployed on my local for testing purpose.
I'm trying to access this web method from diffent windows application, default connection works fine but the other database throw's exception.

Problem is only my defaultDatabase is works fine, if I change defaultDatabase="MYCON1" with "MYCON2" it works fine, if I try to access the other database which is not default, throws exception.

<dataConfiguration defaultDatabase="MYCON1" />
<connectionStrings>
<add name="MYCON1" connectionString="Data Source=server1;Initial Catalog=dbName1;User Id=Username1;Password=password1;"
providerName="System.Data.SqlClient

" />
<add name="MYCON2" connectionString="Data Source=Server2;Initial Catalog=dbName2;User Id=Username2;Password=password2;"
providerName="System.Data.SqlClient" />
</connectionStrings>


Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>(); --> works fine for the default database (MYCON1)


Database myDB=EnterpriseLibraryCo

Error in / Application after adding employee search in webpart

  

Hello everyone,

I am working on sharepoint 2007 and I was editing the webpart of the software and after adding the predefined employee search table, the server has crashed while trying to access the server remotely with the following error message:

Error in / Application

However, while trying to login locally I have no problem and can easily login.

What will be the course of action in fixing this error.

Also the site is complaining of an invalid certificate even after adding an exception.

Any help would be greatly appreciated.


Thank You,

Chris Stanko


Error connecting using SPSite

  
Has anyone seen this error message?

The Web application at http://ecnet/Pages/Default.aspx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

Errors on the line.

SPSite site = new SPSite("http://ecnet/Pages/Default.aspx");


It's a clean console application running on the SharePoint 2007 web server.

Any thoughts? I can't seem to connect to the Server like I used to in SharePoint 2003.

Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+

  

Hi,

This is what I'm trying to do when I get the error on the server (it works on my local machine):

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 
image.Dispose();

Response.ContentType = "image/bmp";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
bmp.Dispose();

I don't think it can be a permissions problem because this works on the server:

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);
image.Dispose();

Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();

So how do I get this to work for a bitmap?

Thanks,
Dan


Login to SPSite\SPWeb through console app using user/password

  
Hi,I'm developing some basic console application which interacts with SharePoint site through the object mode. I'm using:SPSite site = new SPSite(MySiteUrl); SPWeb web = site.OpenWeb(); This way, current windows user is acessing the site. Is it possible to supply the user with username/password to be able to acess with different credentials than current?Thanks in advance!

Error Occured during workflow

  
Hi, i have created a workflow using VS2010 and deployed in SP2010 but while running the workflow its giving me a status message " ERROR OCCURED" my scenario is :  once we upload a document in library it should be copy to another site's or sub site's document library.  can i create a workflow using SPD2010 for this requirement? let me know if anybody have answer.   thanks share2010        

First Development Program with SPSite, SPWeb and SPList works only locally but not in farm

  
Dear All, Here is a piece of code which wrote in a VS 2010 with Standlone Sharepoint 2010 in Windows 7 64 bit and it works fine. Private Shared _SiteURL As String     Private Shared Sub Initialize(ByVal SiteURL As String)                 _SiteURL = SiteURL         Using sc As New SPSite(_SiteURL)             Dim spWebSite As SPWeb = sc.RootWeb             _AllSPList = New List(Of String)             _HiddenSPList = New List(Of String)             _VisibleSPList = New List(Of String)             For Each item As SPList In spWebSite.Lists                 _AllSPList.Add(item.Title)                 If item.Hidden = True Then                     _HiddenSPList.Add(item.Title)             &nb

disposing SPSite and SPWeb objects?

  
hi          can i code using(SPSite oSite=SPContext.Current.Site) {    using(SPWeb oWeb=oSite.OpenWeb()) {} } or should i code like this SPSite oSite=SPContext.Current.Site; using(SPWeb oWeb=oSite.Openweb()){} which is better? i am trying to code this inside ItemAdding Event handler. please suggest

Get xhr object in vb.net when error occured in ajax call using JQuery.

  
Hi Dude,   I have a big problem in Jquery ajax call. I am calling the web service whenever click the update button. I have a separate web service class, in which consist of few methods. When I calling the web service method, I have made the error handling and log the error information in db after that I have to override the "ex" that means error object to XMLHttpRequest. Is it possible to assign the sqlexception to ajax object (xhr) in vb.net? Please help me its much more useful for me.   Thank in advance.

RSS Viewer webpart error

  
Hi, I am trying to add RSS feed to RSS viewer webpart, I got the following error ProtocolError occured trying to complete the request. The server returned a status code of : ProxyAuthenticationRequired and the status description is : "Proxy Authentication Required" Please any one can help me Thanks

An unexpected error has occured

  
Hello I am using following sample code for some testing using Sharepoint 2010     SPSite siteColl = SPContext.Current.Site;     SPWeb site = SPContext.Current.Web;     string ListId = Request.QueryString["List"];     string ItemId =  Request.QueryString["ItemId"];     txtListId.Text = ListId;     txtItemId.Text = ItemId;     SPList list1 = siteColl.RootWeb.Lists["Tasks"];     Response.Write(ItemId.ToString());          SPListItem item1 = list1.Items.GetItemById(Convert.ToInt32(ItemId)); I am getting following error "An unexpected error has occured" in following line, please advise whats wrong I am doing here     SPListItem item1 = list1.Items.GetItemById(Convert.ToInt32(ItemId));

Error when programmatically connect filter webpart with excel webpart

  
Hello, On MOSS 2007 SP2 64bit I am trying to programmatically connect a SPSlicerTextWebPart with an ExcelWebRenderer but I am getting the error: "The connection point "IFilterValues" on "g_046273fe_af27_4064_86b1_70f2c57c326c"(the excel webpart)   is disabled" and I can't find a way to enable it... I'm using the folowing code: using(SPLimitedWebPartManager webPartMgr = web.GetLimitedWebPartManager("Stats.aspx", PersonalizationScope.Shared)) { Microsoft.SharePoint.Portal.WebControls.SPSlicerTextWebPart filterWebPart = (Microsoft.SharePoint.Portal.WebControls.SPSlicerTextWebPart)webPartMgr.WebParts[0]; if (filterWebPart.ConnectionID == Guid.Empty) { filterWebPart.ConnectionID = Guid.NewGuid(); } webPartMgr.SaveChanges(filterWebPart); ProviderConnectionPoint providerCP = webPartMgr.GetProviderConnectionPoints(filterWebPart)[0]; Microsoft.Office.Excel.WebUI.ExcelWebRenderer excelWebPart = (Microsoft.Office.Excel.WebUI.ExcelWebRenderer)webPartMgr.WebParts[1]; if (excelWebPart.ConnectionID == Guid.Empty) { excelWebPart.ConnectionID = Guid.NewGuid(); } excelWebPart.AllowConnect = true; webPartMgr.SaveChanges(excelWebPart); ConsumerConnectionPoint consumerCP = webPartMgr.GetConsumerConnectionPoints(excelWebPart)[2]; TransformableFilterValuesToFilterValuesTransformer t = new TransformableFilterValue

MOSS 2007 SP2 Error after 3rd party Webpart uninstallation

  
To All Experts out there, How to remove the error message of the uninstalled 3rd party webparts from the WFE server ? I got this error message almost all the time everyday ?   ####################################################################################################################################################Log Name:      ApplicationSource:        Windows SharePoint Services 3Date:          8/09/2010 10:10:48 PMEvent ID:      7043Task Category: Web ControlsLevel:         ErrorKeywords:      ClassicUser:          N/AComputer:      MOSSDEV01.domain.comDescription:Load control template file /_controltemplates/BambooVisualIndicatorFieldEditor.ascx failed: Could not load file or assembly 'RadAjax.Net2, Version=1.8.5.0, Culture=neutral, PublicKeyToken=3f7b438d1c762d0b' or one of its dependencies. The system cannot find the file specified.####################################################################################################################################################Log Name:      ApplicationSource:        Windows SharePoint Services 3Date:          8/09/2010 10:09:40 PMEvent ID:      6611Task Category: RuntimeLevel: &nbs

Export-SPWeb "cannot find spweb object with id or url" error

  
How do we just export and import a library or a list using Export-SPWeb and Import-SPWeb? I tried exporting just a library with Export-SPWeb, but it throws an error : Could not find an SpWeb Object with Id or URL “http://<server:port>/Shared Documents”. The same thing goes for a simple list like Tasks: "http://<server:port>/Lists/Tasks". Any help would be much appreciated

Changing Properties/Attributes of a Webpart in inline code block - Error 'System.Web.UI.WebControl

  
I'm trying this code below, but gettting error: System.Web.UI.WebControls.WebParts.WebPart' does not contain a definition for 'FilterValue1' I need to change the value of the FilterValue1 properties of a content Query WebPart with title = Applicant Files. Thanks in Advance!
protected override void OnLoad(EventArgs e) {  base.OnLoad(e); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite SiteCollection = new SPSite("https://somesite/")) { SPWeb myWeb = SiteCollection.OpenWeb(); myWeb.AllowUnsafeUpdates = true; Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null; mgr = myWeb.GetLimitedWebPartManager("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts) { if (myWebPart.Title == "Applicant Files") { myWebPart.FilterValue1 = "/13"; mgr.SaveChanges(myWebPart); break; } } } }); }

179 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage.

  
Hi All, I am gettings hundreds of following error messages in my sharepoint log files 179 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage. Also I have noticed that after these error messages my sharepoint site is now dead slow. Any idea how to resolve this problem ?  
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend