Thursday, December 17, 2009

CommonViewFields - String Formatting Issue

CommonViewFields property allows you to include additional columns to the filter or display of the Content Query Web Part. You can provide semi-colon separated list of columns and column names are separated from datatype by a comma.


<property type="string" name="CommonViewFields"> ArticleStartDate, Date;Countcomments, lookup;PageURL, lookup;</property>


There is a known bug to this. In some specific SP environments while importing the web part with the format above you might receive an error. This is because of the formatting of the string. You need to remove all white space and also the “;” from the last colunmname-datatype pair.


<property type="string" name="CommonViewFields"> ArticleStartDate,Date;Countcomments,lookup;PageURL,lookup </property>

Thursday, November 12, 2009

Trying to use an SPWeb object that has been closed or disposed and is no longer valid

You receive the above error while trying to edit a WebPart page which uses a custom WebPart with SharePoint API. As per the best practices recommendation, some of the WSS objects like SPWeb & SPSite need to be disposed programmatically to avoid memory leaks as they use unmanaged code and memory to perform their operation. In C# the best way is to use “using” statement for this purpose as the common language runtime translates using clauses into try and finally blocks, and any objects that implement the IDisposable interface are disposed for you.

However, there are some special cases where you should not dispose the object programmatically. The following code example shows one case where you would not want the runtime to construct a finally block and dispose objects for you


using( SPWeb web = SPControl.GetContextWeb(HttpContext.Current)) { ... }


This is because SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.

You receive the “Trying to use an SPWeb object that has been closed or disposed and is no longer valid” when page is in edit mode if you tried to dispose SPContext retrieved objects.

http://msdn.microsoft.com/en-us/library/aa973248.aspx

Thursday, September 4, 2008

The Web application at (URL) could not be found

I received the following error : The Web application at (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 while trying to access sharepoint site collection using sp api from an asp.net web application.

This was happening because the ASP.net application pool identity did not have enough previlages. Changing asp.net application pool to run under same identity as MOSS application fixed the issue.

More details can be found at Dragon Panjkov's blog.

http://www.sharepointblogs.com/panjkov/archive/2007/10/18/asp-net-moss-and-app-pool-identities.aspx

Thursday, August 28, 2008

The security validation for this page is invalid

Error:

I received the following error while uploading files to a sharepoint document library from an asp.net application.
The security validation for this page is invalid. Click Back in your Web
browser, refresh the page, and try your operation again
Resolution:

Add following lines of code before the Update() method on SPFolder is called.

site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;

Wednesday, August 27, 2008

Multiple Copies of Sharepoint Web application

To create multiple copies of a web application on a webfarm the database backup-restore will not work as the GUID of site will be same. The following process is useful in that scenario:


  • Back up using stsadm stsadm -o backup -url <original site url> -filename <backup file path>\db.bak
  • Create new web application (and content database) using Central Admin
  • Restore (and overwrite) using stsadm stsadm -o restore -url <new site url> -filename <backup file path>\db.bak -overwrite