26 August 2011

Override the render function of the SharePoint content editor WebPart

Had you come across on Bug of the SharePoint Content Editor WebPart
So there is interesting problem
If using external links and internal links – you will get the bug
An example to the bug:
Try This - Internal links, external links and internal links again

What we get is the first two links work correctly, but the third link will link us to link the internal server name we have created the site. This is big bug for CEWP.
Hope you understood the bug.

How do we solve it? You can not inherit the WebPart - then shall we do?
Built Control Adapter performs render the code.
Create a small project in Visual Studio that contains the following code

using System;
using
 System.Collections.Generic;
using
 System.IO;
using
 System.Text;
using
 System.Web.UI;
using
 Microsoft.SharePoint;
using
 Microsoft.SharePoint.Administration;
namespace
 Roi.Moss.ControlAdapter.ContentEditorWebPart
{
  public class ContentEditorWebPartAdapter : System.Web.UI.Adapters.ControlAdapter
  {
    ///
 <summary>
    ///
 Override the render function off the CEWP
    ///
 </summary>
    ///
 <param name="writer">HtmlTextWriter write</param>
    protected
 override void Render(HtmlTextWriter writer)
    {
      //Create a new stringbuilder

      StringBuilder
 sb = new StringBuilder();
      //create a HtmlTextWriter

      HtmlTextWriter
 htw = new HtmlTextWriter(new StringWriter(sb));
      //Preform the base Render Method

      base
.Render(htw);
      //Get the output string

      string
 output = sb.ToString();
      //Create a list with the alternate access urls

      List
<Uri> alternateUrls = GetCurrentAlternateAccessMappingsUrls();
      //Read out the list with alternate access urls

      foreach
 (Uri alternateUrl in alternateUrls)
      {
        //Replace the url's with /

        output = output.Replace(alternateUrl.ToString(), "/");
      }
      //write the output to the page

      writer.Write(output);
    }
  }
}

The function GetCurrentAlternateAccessMappingsUrls has been showed last month.
Now pass the code to the GAC. On the folder of IIS which at App_Browsers folder.
For example C: \ Inetpub \ wwwroot \ wss \ VirtualDirectories \ 80 \ App_Browsers
Now you need to add the following code in a file compat.browser
<browsers>
  ...
  <
browser refID="Default">
    <
controlAdapters>      <adapter controlType="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart"                 adapterType="Roi.Moss.ControlAdapter.ContentEditorWebPart.ContentEditorWebPartAdapter, Roi.Moss.ControlAdapter.ContentEditorWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f86d098a47bbaa6" /&amp;gt;
    </
controlAdapters>
  </
browser>

  ...
</
browsers>

Hope I helped
Roi

22 August 2011

There was an exception running the extensions specified in the config file. ---> Maximum request length exceeded.

Have you ever encountered the following message when you try to transfer large data in web service?

There was an exception running the extensions specified in the config file. ---> Maximum request length exceeded.

:)

All you need to do is:
Access to the remote server where the is WebService.
Go to the web.config and set the tag httpRuntime the following code on the "system.web" tag.

<system.web>
  <httpRuntime executionTimeout="999999" maxRequestLength="51200">
...

Roi

14 August 2011

How to Create a validation to a list form for "Attach File" for SharePoint

Sometimes the little code - works!
How to do on MOSS 2007 list form a requirement to the attach field?

 

Let build up a validation in JavaScript

The following JS code do it perfectly. All you need is access to the SharePoint Designer. Edit the form (NewForm.aspx or EditForm.aspx). Find a good place to insert the code in the list form, And Copy-Paste the code:
<script type="text/javascript" language="javascript>
function
 PreSaveItem() {
  var elm = document.getElementById("idAttachmentsTable");
  if
 (elm == null || elm.rows.length == 0)
  {
    alert("Please attach a document to the request");
    return
 false;
  }
  if ("function" == typeof (PreSaveAction))
  {
    return
 PreSaveAction();
  }
  else
    return
 true;
}
</
script>

I Love JavaScript
Roi

12 August 2011

Failed to extract the cab file in the solution / Root element is missing

Did you encounter the following error message?

Failed to extract the cab file in the solution.

I came across this message - in my case it was install a solution.


Another problem I had with the solution

Root element is missing.



After thorough testing - I found the solution
The Size of File wss.xsd was 0k
Is the stsadm command uses this file ????.... Yes!

All you need do is to copy from server that work correctly the file wss.xsd.

Those who do not know the file is sitting in
12Hive \TEMPLATE\XML for MOSS 2007
14Hive \TEMPLATE\XML for SharePoint 2010
The file is responsible for all schema of the SharePoint.

Hope I helped,
Roi Kolbinger

09 August 2011

How to get updates of changes to the database

Have you ever encountered in developing longer and you do not remember what you did and what updated and created.
No - then you can not continue reading the article.
If so - and also worked with a database ...

So probably you wanted to know what you did (and don't remember)
Here's a query that returns all the tables,views,stored procedures and functions which have changed in the last 30 days (you can change 30 to any number)

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:        Roi Kolbinger
-- Create date:   02/08/2008
-- Description:   Get tables,views,stored procedures and functions that modified for 30 days
-- =============================================
ALTER PROCEDURE [dbo].[GetAllDBDetails]
AS
BEGIN
-- ======================views=======================
SELECT name AS view_name
  ,SCHEMA_NAME(schema_id) AS schema_name
  ,OBJECTPROPERTYEX(object_id,'IsIndexed') AS IsIndexed
  ,OBJECTPROPERTYEX(object_id,'IsIndexable') AS IsIndexable
  ,create_date
  ,modify_date
FROM sys.views
Where modify_date &gt; (getdate()-30)
-- ======================tables=======================
SELECT name AS table_name
  ,SCHEMA_NAME(schema_id) AS schema_name
  ,OBJECTPROPERTYEX(object_id,'IsIndexed') AS IsIndexed
  ,OBJECTPROPERTYEX(object_id,'IsIndexable') AS IsIndexable
  ,create_date
  ,modify_date
FROM sys.tables
Where modify_date &gt; (getdate()-30)
-- ======================stored prordures=======================
SELECT name AS procedures_name
  ,SCHEMA_NAME(schema_id) AS schema_name
  ,OBJECTPROPERTYEX(object_id,'IsIndexed') AS IsIndexed
  ,OBJECTPROPERTYEX(object_id,'IsIndexable') AS IsIndexable
  ,create_date
  ,modify_date
FROM sys.procedures
Where modify_date &gt; (getdate()-30)
-- ======================functions=======================
SELECT name AS function_name
  ,SCHEMA_NAME(schema_id) AS schema_name
  ,type_desc
  ,create_date
  ,modify_date
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%'
and modify_date &gt; (getdate()-30)
END


The result

To see more  examples - use this line : http://msdn.microsoft.com/en-us/library/ms345522.aspx

Yours,
Roi