Using CommonShowModalDialog in SharePoint

I’ve not found any post explaining the usage of CommonShowModalDialog in SharePoint, the default popup used by SharePoint across the board. So I thought why can’t I make one.

The method exists in core.js and it is used OOTB by SharePoint for opening popups in places like selecting a web application from a list of web applications, selecting a site collection from a list of site collections etc. (you could see these in Central administration). So here is the method –

function openPopup(){
    commonShowModalDialog("/_layouts/selectitem.aspx", "resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:410px; dialogHeight:300px;", RetrieveItemValue);
}

CommonShowModalDialog has similar parameters as a simple window.open().

  1. Target URL
  2. Window features
  3. Callback function

To pass a value from the popup to the parent page use window.returnValue in te popup to save the value before closing the window.

//called from the popup page
function closePoup(){
    window.returnValue = myValue;
    window.close();
}

Retrieve the value passed from the popup in the callback function mentioned.

//Retreives the value sent from the popup
function RetrieveItemValue(retValue) {
    alert(retValue);
}

As simple as that.

Advertisements

Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

Hi all,

I was working with a webpart in MOSS and I created my custom toolpart for configuring the web part. Once, when I was trying to save the settings, I got the error – “Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))”. I was confused and when I tried to debug the webpart I was not hit by any exceptions.

After crawling through some articles I found that I was disposing the SPWeb and SPSite objects which stores the current context of the site. So I removed all the code disposing the SPWeb and SPSite objects STORING THE CURRENT CONTEXT OF THE SITE (you have to dispose the usual SPSite and SPWeb objects with Using statements or disposing them in the ‘finally’ blocks). And bingo, it worked.

You may also get the following error

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

while trying to add a webpart.

So never dispose those objects when they belong to the current context.

Me

Hitting 401 – Unauthorized for FBA enabled sites in SharePoint

Among the multitude of issues I faced in the process of creating an internet facing publishing portal in SharePoint, this one was killing me for a couple of days.

After extending my web application to intranet zone, i enabled FBA authentication with anonymous access in my default zone. The strange thing i noticed is that if you open a page for the first time, you’ll hit a page showing 401 – Unauthorized error. But if you refresh the page in your browser, the page loads fine in anonymous mode. Each and every ‘postbacks’ in your pages will face the same issue. After hours of googling and found the solution for the problem. To get rid of the issue

1. Change <compilation batch=”true” debug=”true”> to <compilation batch=”false” debug=”false”> in your web.config.

2. Allow anonymous access in the windows authentication zone. To do that follow these steps.

  • Go to Central Administration -> Application Management -> Authentication Providers
  • Select your web application
  • Choose the appropriate zone which is configured to use windows authentication
  • Check ‘Allow anonymous access’
  • Click OK

Whoomp! The issue is gone.

Delete Extended Web applications in SharePoint

I was in the process of migrating a MOSS publishing site to a production server. I extended the site to intranet zone to have the default zone to be configured for FBA authentication. While extending the site I made a typo while specifying a host header for the site. When I tried to delete the extended web application by selecting it from the web applications list in CA I was not able to find the extended application’s entry. Then I googled for a while to find a solution and found it here – http://sharepointnotes.wordpress.com/2008/07/17/quick-tip-delete-extended-web-application/.

To delete an extended web application,

1. Go to Central Administration -> Application Management -> Remove SharePoint from IIS Web Site

2. Select the original web application from the list

3. Select the appropriate extended application to delete

4. Press OK

WSS Logs sizes growing ridiculously

Hi all,

Recently I did a fresh installation of SharePoint 2007 in a standalone system and applied all the service packs and cumulative updates released. After working in the server for 2-3 days I noticed the free space of the SharePoint installation drive going down at a very high rate. I lost over 5.5 GB of the free space in the disk over the past two days. I installed this handy tool to investigate the sizes of the folders residing in the drive. To my surprise, I found out the ’12 Hive’ occupying around 6 GB of the disk space. When I opened it to check the individual sizes of its sub folders I found that the whole space is taken by the LOGS folder. It contained around 3-4 files sizing over a GB. I stopped the WSS Tracing service in the services and deleted all the XL log files. But when I switched on logging it started growing again. I googled out the issue for a few minutes and found this useful post – http://blogs.vertigo.com/personal/steventap/Blog/archive/2007/01/19/managing-sharepoint-2007-moss-application-log-size.aspx dealing about this issue. The solution is just to configure the Diagnostic Logging in Central Administration -> Operations -> Diagnostic Logging. I just configured ‘Least Critical Event to report to the trace log’ to be medium, since I’m working in a dev environment. You can configure it according to your server’s nature such as production, staging etc.

Adding custom Code Access Security (CAS) policy in SharePoint

While writing some code behind (aside) for our custom SharePoint pages, we often run into the Security Exception error after placing the dlls in the bin folder in the site’s virtual directory. This is because of the trust level provided to the dlls and we fix it by simply changing the trust level to full in the web.config file. Even though it fixes the issue it opens up a security whole in your application by providing access to all the dlls to execute. The best way is to create our own custom policy file and hooking it up in the web.config file. Follow the below steps to create you own CAS policy.

1. Open the 12 hive and navigate to the config folder.

2. Copy the contents of the wss_mediumtrus.config to another file with your custom name custom_policy.config.

3. Now create your code group and add your dll with PermissionSetName set to FullTrust. Add all your dlls in the same way in the file. Below is a part of my custom policy file with codegroups defined for the dlls.

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_activation.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_registration.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_fpassword.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_myaccount.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_myprofile.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/bin/App_Web_purchasehistory.aspx.cdcab7d2.dll"/>
</CodeGroup>

<CodeGroup version="1" PermissionSetName="FullTrust">
<IMembershipCondition version="1" Url="$AppDirUrl$/_app_bin/*">
</CodeGroup>

4. Navigate to your site’s virtual directory and open the web.config file.

5. Add the custom policy file as follows.

<securityPolicy>
<trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_mediumtrust.config" />
<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_minimaltrust.config" />
<trustLevel name="Custom_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\Custom_minimal.config" />
</securityPolicy>

6. Set the trustlevel to point to your custom policy.

<trust level="Custom_Minimal" originUrl="" />

7. Do an IISRESET.

As simple as that :). Note that i’ve specified each and every dll separately in the policy file. If you want all the dlls in the bin folder to be added in the policy simply give it as bin/* in the code group.

Access denied error during login in IE after migrating a SharePoint Publishing Portal

Recently i faced this problem while trying to migrate a publishing portal using stsadm backup and restore commands. I was hit by a strange problem where i wasn’t able to login into the site even with the administrative account. But i was able to login when i opened the site in Google Chrome and Firefox (?!). Finally after googling it out and going through the MSDN forums i found that it was due to some Windows Server Security patch.

You can find the fix for the issue here – http://support.microsoft.com/default.aspx/kb/896861.

The MSDN discussion link about the issue – http://social.technet.microsoft.com/Forums/en-US/sharepointadmin/thread/e044ed41-2be8-4e1c-8bcf-6460c0f0c777.