Thursday, October 28, 2010

Custom Enterprise Search Webpart in SharePoint 2007

Normally we use out of the Box SharePoint Search, but sometimes there is custom requirement in which we need to use Custom Search Webpart.
Here is a small portion of code to write for custom Enterprise Search Webpart.
Sample Code:

protected System.Web.UI.WebControls.DataGrid grdEntrerpriseSearchResults = new DataGrid();

protected override void CreateChildControls()
{
string strSearchQry;

using (SPSite site = new SPSite(SPContext.Current.Site.Url .ToString()))
            {
               strSearchQry = BuildFullTextSqlQuery(false);
Microsoft.Office.Server.Search.Query.FullTextSqlQuery qryFullText = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(site);
               qryFullText.QueryText = strSearchQry;
               qryFullText.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
               qryFullText.TrimDuplicates = true;
               qryFullText.EnableStemming = true;
               qryFullText.RowLimit = 50;
               qryFullText.Timeout = 120000;
               Microsoft.Office.Server.Search.Query.ResultTableCollection results = qryFullText.Execute();
               Microsoft.Office.Server.Search.Query.ResultTable relevantResults = results[Microsoft.Office.Server.Search.Query.ResultType.RelevantResults];
               DataTable resultsDataTable = new DataTable();
               resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges);
               grdEntrerpriseSearchResults.DataSource = resultsDataTable;
               grdEntrerpriseSearchResults.DataBind();

            }

            this.Controls.Add(grdEntrerpriseSearchResults);
        }

        private string BuildFullTextSqlQuery(bool bDocumentsOnly)
        {
            string sRetval = string.Empty;
            string sSelectQuery = "SELECT Title, Path, Size, HitHighlightedSummary FROM Scope() ";
            string sWhereQuery = string.Empty;

            sWhereQuery = " WHERE (\"SCOPE\" = 'SiteName') AND (IsDocument=1) ";

           if (bDocumentsOnly == true)
                 sWhereQuery = " WHERE IsDocument=1 AND (\"SCOPE\" = 'All')";
             else
                 sWhereQuery = " WHERE IsDocument=0 AND (\"SCOPE\" = 'All')";
      
            sWhereQuery += " AND FREETEXT(*, 'Keyword') ";
            string sOrderByQuery = "  ORDER BY Rank DESC ";
         
            if (bDocumentsOnly == false)
            {
                sWhereQuery += " AND ContentClass='STS_Web'";
            }

            sRetval = sSelectQuery + sWhereQuery + sOrderByQuery;
        
            sRetval = sSelectQuery + sWhereQuery + sOrderByQuery;
            return sRetval;
        }

Disha Shah

Free ebook: Moving to Microsoft Visual Studio 2010

Download Free Ebook - "Moving to Microsoft Visual Studio 2010"  from this location

http://blogs.msdn.com/b/microsoft_press/archive/2010/09/13/free-ebook-moving-to-microsoft-visual-studio-2010.aspx

Enojy
Disha Shah

Restricted Characters For SharePoint Environment

Restricted Characters For SharePoint Environment:
  • SharePoint sites can not include the following characters:
    \ / : * ? “ < > | # { } % & <TAB>.
  • The following characters cannot be used in the naming of files to be uploaded to SharePoint:
    “ # % & * : < > ? \ { } | ~ _
  • SharePoint file names cannot exceed 128 characters in length.
Disha

    Change CSS in Sharepoint Master Page File depends on Current Browser and Current Platform

    Hello,
    One CSS will never work for every platform and Browser for same look and feel of the application, we need different CSS depends on platform and Browser, because every browser has their own behavior.
    So for Consistent Look and Feel Across the platform, we have to assign the appropriate CSS depends on detecting platform and browser , and we have to tell master page which css they have to refer so it gives nice look.
    To solve this problem, we have written one webpart named as "Browser Finding” and that webpart has been added in master page of the application.
    By these lines, it will identify the current browser and platform
    string currentUserBrowser = this.Context.Request.Browser.Browser;
    string currentUserPlatform = this.Context.Request.Browser.Platform;
    Let us see some code of portion of the code.
    HtmlGenericControl linkNewCore = new HtmlGenericControl("link");
    HtmlGenericControl linkMyStyleSheet = new HtmlGenericControl("link");
    linkNewCore.Attributes.Add("rel", "stylesheet");
    linkMyStyleSheet.Attributes.Add("rel", "stylesheet");
    linkNewCore.Attributes.Add("type", "text/css");
    linkMyStyleSheet.Attributes.Add("type", "text/css");
    linkNewCore.Attributes.Add("href", "/Style Library/newcore.css");
    linkMyStyleSheet.Attributes.Add("href", "/Style Library/gso-search.css");

    string sUniqueQuery = "?rev=" + Guid.NewGuid().ToString().Replace("-", "");
    string currentUserBrowser = this.Context.Request.Browser.Browser;

                switch (currentUserBrowser)
                {
                    case "AppleMAC-Safari":
                        linkMyStyleSheet.Attributes.Add("href", "/Style Library/Safari.css" + sUniqueQuery);
                        break;
                    case "Firefox":
                        switch (currentPlatform)
                        {
                            case "Unknown":
                                linkMyStyleSheet.Attributes.Add("href", "/Style Library/Netscape_Mac.css" + sUniqueQuery);
                                break;
                            default:
                                linkMyStyleSheet.Attributes.Add("href", "/Style Library/Netscape.css" + sUniqueQuery);
                                break;
                        }
                        break;
                    default:
                        linkMyStyleSheet.Attributes.Add("href", "/Style Library/Custom.css" + sUniqueQuery);
                        break;
                }
                this.Controls.Add(linkNewCore);
                this.Controls.Add(linkMyStyleSheet);
    Disha Shah

    Tuesday, October 26, 2010

    Overview of SharePoint 2010 Central Administration

    Hi Friends
    I have installed the SharePoint 2010 on my AMD 32 bit machine.
    This is the Central Administration Screen of SharePoint 2010.Doesn’t it looks cool? Yes It is.
    It also provides many fantastic features. Let us look at some of features overview by Sections.

    Application Management
    This is the one of the section where we perform a number of operations like create new Web applications and site collections,  manage the services that are installed on SharePoint site like Excel Services or BCS ,manage content database. (The content database is the database which stores SharePoint data per web application wise, and is the reason why SharePoint takes a dependency on SQL Server upon installation.)
    Application management provides so many options by which we can accomplish tasks such as

    1. Modifying the properties of the content database
    2. Activating features, creating new site collections
    3. So many J
    Let us display names of all sections under Application Management.


    Monitoring 
    Monitoring is a section where we can manage reporting, monitoring, and the status of your SharePoint site.
    The Monitoring site has main three portions:
    Ø  Review problems and solutions or Health status: Health status provides a place for you to manage the status of different services on your SharePoint server (such as Visio services or farm-level services). You can see which services are failing, for example, through reports that are surfaced here. Health status also enables you to define rules (such as the scheduling of application pool recycles). View the problems detected by the SharePoint Health Analyzer and take steps to solve those problems.
    Ø  Timer jobs: we can provide details for a specific timer jobs to run, and when to run them and view the status and results for the last execution of timer jobs that are enabled in the farm.
    Ø  Reporting:Reporting provides you with a set of tools that enables you to create and manage reports, run diagnostic logging, and view reports on various server-side activities. View traffic, search, or inventory statistics for web applications in the farm.

    General Application Settings

    It is the place where we can configure a number of generic settings for a SharePoint site collections and sites.
    Security

    It provides and covers so many security areas for SharePoint like management of administrator accounts, configuration and management of service accounts, the management of password change settings and policies, and the specification of authentication providers, trusted identity providers, antivirus settings, blocked file types, Web part security, self-service security, and secure token services. The security settings here supplement the security in the main browser UI, where users and site administrators can assess specific permissions that relate to users for their sites.
    Ø  Manage the farm administrators group: Manage the farm administrators group. Members of this group have complete access to all settings in the farm and can take ownership of any content site.
    Ø  Configure service accounts: Manage the credentials this farm and associated services use.
    Ø  Configure send to connections
    Ø  Configure content deployment paths and jobs
    Ø  Manage form templates

    System Settings
    It allows us to configure more server-centric settings like farm-level or access features, manage the services.
    Ø  Manage servers in this farm: Configure and enable services to run on the local farm.
    Ø  Manage services on server: Select the services that will run on each server in the farm.
    Ø  Manage farm features:Enable or disable farm-wide SharePoint functionality.
    Ø  Configure alternate access mappings:Configure the internal and public URL mapping for web    applications in the farm.

    Backup and Restore
    The place which gives ensured of that we can recover our sites in case of failure. It allows us to create and schedule regular backups for your SharePoint, perform ad hoc backups, restore from a previously backed-up SharePoint site, and so on
    Ø  Perform a backup:Back up portions of this farm to a file.
    Ø  Restore from a backup:Restore content to this farm using a backup file.
    Ø  Perform a site collection backup: Back up the contents of a site collection.
    Upgrade and Migration

    Sometimes organization needs to upgrade their SharePoint Standard Edition to SharePoint Enterprise Edition which requires a license and a server-driven process to upgrade one version of SharePoint to another. This place of Central Administration gives this facility.
    Ø  Convert farm license type
    Ø  Check product and patch installation status: View the current product and patch installation status.
    Ø  Check upgrade status: View the status of current and previous upgrade events.
    Configuration Wizards

    A step-by-step wizard that configures SharePoint server for us.


    Saturday, October 23, 2010

    Sharepoint Web Application Settings for Upload Big Size Files in Windows Server 2008 with IIS 7.0 Version

    Hello Friends

    On a Windows Server 2008 computer that has IIS 7.0-only installations, you add the maxAllowedContentLength value. When you are running Windows SharePoint Services on a Windows Server 2008-based computer that has IIS 7.0, you find that you cannot upload files that are larger than 28 MB even though you have configured the large file upload settings. Usually, the error that users see is "The page cannot be displayed." In some circumstances, users may also see an "HTTP 404" error.

    To work around this problem, set in the Web.config file for the Web application to have following settings under the <configuration> section:
    •       Use Notepad to open the Web application Web.config file. By default, this file is in the following folder: Inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectoryFolder
    •       Add the following settings under the <configuration> section of the Web.config file: <system.webServer><security><requestFiltering><requestLimits maxAllowedContentLength="52428800"/></requestFiltering></security></system.webServer>
    Note maxAllowedContentLength="52428800" in bytes has to match the size of file that you are trying to upload. Also, when you set the number, increase it slightly beyond the maximum file upload size that you have configured in SharePoint. If the number is equal to or less, users will not receive the error message that they are exceeding the size limit if they try to upload a file size larger than that specified by the administrator.

    This value is set is 
    maxAllowedContentLength="2146435072"


    Refer this article for more details http://support.microsoft.com/kb/925083
    Disha Shah

    Upload Big Size Files In Sharepoint Applications

    Hello Friends
    Let us see what we need to make changes for uploading Big Size files for Sharepoint Applications. Here
    are the changes which we need to make in web.config files and Central Administration.
    1>     Open the Web.config file of this webapplication by going to Local Drive:\Inetpub\wwwroot\wss\VirtualDirectories\SharepointTestApplicationPortNumber(example 80)
    2>     Find < httpRuntime and replace that line with the following line.
    <httpRuntime  executionTimeout="999999" maxRequestLength="2097151"   />
    3>     Go to Sharepoint  3.0 Central Administration à Application Management à Under Sharepoint WebApplication Management you find “WebApplication General Settings”.
    4>     Click on that.
    5>     Change the proper sharepoint test webapplication .
    6>     In that there is one option “Maximum Uplod Size”  50 MB is by default , make it Enter 2047.
    7>     Click OK

    Thanks
    Disha Shah

    Error Resolution For COM Error For Sharepoint Application on Windows Server 2008 64 Bit

    Hello Friends
    Retrieving the COM class factory for component with CLSID {BDEADEE2-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa
    We have noticed that this error occurs only on SharePoint 2007/Windows 2008 64 Bit server. The error pattern is kind of strange, application will work fine initially and then intermittently server will start throwing "COM Class factory" Error. As of now we did not find any set of steps to reproduce this error. The only quick resolution we have found during research is to perform IISRESET and error will go away. The Error will again reappear after 1-2 days. Finally after opening case with Microsoft support and extensive research we got the resolution. Please follow the steps –
    1.       To open IIS 7 Manager from the Start menu
    1.   Click Start, and then click All Programs.
    2.   Click Administrative Tools, and then click Internet Information Services (IIS)    Manager.
    3.   To open IIS Manager from the Search box
    4.   Click Start.
    5.   In the Start Search box, type inetmgr and press ENTER.
    2.   Access Application Pools within IIS manager. Find and select “Application Pool” for your  SharePoint application. 
    3.   Click “Advanced Settings” from Actions menu. You will be presented with settings window. Find “Load User Profile” settings under “Process Model” section. By default the value is set to “False”. Change it to “True”.
    4.   Click “OK” to save the settings. Exit IIS manager from File->Exit.
    5.   Changing Load User Profile setting from FALSE to TRUE will stop Intermittant COM errors.


    Thanks
    Disha Shah

    Error Resolution for Server Authentication Issue with Sharepoint Application which uses Host Headers

    When you create a web application with a host header on SharePoint which is installed on Windows Server 2008, your credentials can not be authenticated if you try to log in to the web application on the server itself; although you can access the site from outside.

    The main reason for this issue is, the system blocks the authentication procedure while resolving the host header given to the web application. To resolve this issue, a modification must be done to the server’s registry.

    To resolve this problem,  Administartor has to perform following steps.
    1.      Click Start, click Run, type regedit, and then click OK.
    2.      In Registry Editor, locate and then click the following registry key:
          HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
    3.      Right-click MSV1_0, point to New, and then click Multi-String Value.
    4.      Type BackConnectionHostNames, and then press ENTER.
    5.      Right-click BackConnectionHostNames, and then click Modify.
    6.      In the Value data box, type the host name or the host names for the sites that are on the local   computer, and then click OK.
    7.      Exit Registry Editor, and then restart the computer.

          Note: For Example if you used Host Header as “sharepointdev” for your sharepoint application then you need to add this name in BackConnectionHostNames box.
    Following are the articles which explains the issue and fix for the same.
    http://vspug.com/nezihtinas/2009/04/21/unable-to-authenticate-to-a-sharepoint-portal-on-the-server-itself/
    http://support.microsoft.com/kb/956158/en-us

    This is known issue with SharePoint 2007 on Windows Server 2008 platform and not specific to any sharepoint application. The above registry modification must be done for all other SharePoint applications which are using Host Header.

    Thanks
    Disha Shah

    Build AJAX Enabled Web Parts in SharePoint 2007

    Hello Friends

    There are so many scenarios where entire Sharepoint 2007 application uses OOTB (out of the box) functionality  but we need to develop some custom webparts which uses AJAX Functionality so rather than making changes in web.config and master pages for entire application , we can write the same thing in the webpart itself in its OnInit function.

    protected override void OnInit(EventArgs e)
    {
    if (ScriptManager.GetCurrent(this.Page) == null)
    {
    scriptManager = new ScriptManager();
    scriptManager.ID = “myScriptManager”;
    scriptManager.EnablePartialRendering = true;
    this.Page.Form.Controls.Add(scriptManager);
    }
    base.OnInit(e);
    }
    Thanks
    Disha Shah

    Thursday, October 14, 2010

    SharePoint 2007 Error: "The path specified cannot be used at this time"

    Hello Friends

    I got this error when I was creating a new Web Application.
     "The path specified cannot be used at this time"

    This error occurs because when it tries to executes Timer Job Services.
    This can be solved by restarting the Windows SharePoint Services Timer service or do IISRESET.

    Happy Error Resolving!!
    Disha Shah