Friday, January 11, 2013

Visual Webpart for Creating Sharepoint Sites

UI:
<div>
    <asp:Label ID="lblSiteName" Text="Site Name: " runat="server" Width="100" />
    <asp:TextBox ID="txtSiteName" runat="server" />

    <asp:Label ID="lblSiteDescription" Text="Site Description: " runat="server" />
    <asp:TextBox ID="txtSiteDescription" runat="server" />

    <asp:Label ID="lblIntendedURL" Text="Intended URL: " runat="server" />
    <asp:TextBox ID="txtIntendedURL" runat="server" />

    <asp:Label ID="lblSiteTemplate" Text="Site Template: " runat="server" />
    <asp:DropDownList ID="ddlSiteTemplate" runat="server"
        onselectedindexchanged="ddlSiteTemplate_SelectedIndexChanged">
    </asp:DropDownList>

    <asp:CheckBox ID="chkUniquePermissions" Text="Unique Permissions " runat="server" />
    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
        Text="Submit" />

</div>

Code:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web;
using Microsoft.SharePoint;

namespace Jan10thVWP1.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        SPWebTemplateCollection wt;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtSiteName.Text == string.Empty && txtIntendedURL.Text == string.Empty)
                return;

            using (SPSite site = new SPSite(@"http://sp2010"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    try
                    {

                        SPSecurity.RunWithElevatedPrivileges(() => web.Webs.Add(
                            txtIntendedURL.Text,
                            txtSiteName.Text,
                            txtSiteDescription.Text,
                            1033,
                            ddlSiteTemplate.SelectedValue,
                            chkUniquePermissions.Checked,
                            false));

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('Success');", true);
                    }
                    catch (Exception ex)
                    {
                        string error = ex.Message;
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + error + "');", true);

                    }
                    finally
                    {
                        txtSiteName.Text = string.Empty;
                        txtSiteDescription.Text = string.Empty;
                        txtIntendedURL.Text = string.Empty;
                    }
                }
            }

        }
        protected override void OnLoad(EventArgs e)
        {

            EnsureChildControls();
            if (!IsPostBack)
            {
                using (SPSite site = new SPSite(@"
http://sp2010"))
                {
                    using (SPWeb web = site.RootWeb)
                    {
                        try
                        {
                            wt = web.GetAvailableWebTemplates(1033);
                            foreach (SPWebTemplate template in wt)
                            {
                                ddlSiteTemplate.Items.Add(new ListItem(template.Title, template.Name));
                            }
                            ddlSiteTemplate.DataBind();

                        }
                        catch (Exception ex)
                        {
                            string error = ex.Message;
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('" + error + "');", true);
                        }
                    }
                }
            }

        }
        protected void ddlSiteTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

Thursday, January 3, 2013

Updating Title of a SharePoint Site / Subsite using SharePoint Object Model

File | New | Project | Visual C# | .Net Frame Work 3.5 | Console Application

Give a Name there: | Choose Location | Click on Ok.

1. Add reference : Microsoft.SharePoint.dll
from the location:
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll

2. Right Click on Console Application Project |
From Application | Target Framework | .Net Framework 3.5
Build | Target Plat from | Either X64 or Any Cpu | Save the changes

Add u r reference :
using Microsoft.SharePoint.dll;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using( SPSite  spSite = new SPSite("http://sp2010:8081") )
            {
                using (SPWeb spWeb = spSite.RootWeb)
                { 
                    foreach (SPWeb subWeb in spWeb.Webs)
                    {
                        subWeb.Title = spWeb.Title + subWeb.Title;
                        subWeb.Update();
                    }
                    spWeb.Title = "Hello" + spWeb.Title;
                    spWeb.Update();
                }
            }
        }
    }
}

 

 

Reading Titles of all the Sub Sites of a SharePoint site collection

File | New | Project | Visual C# | .Net Frame Work 3.5 | Console Application

Give a Name there: | Choose Location | Click on Ok.

1. Add reference : Microsoft.SharePoint.dll
from the location:
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll

2. Right Click on Console Application Project |
From Application | Target Framework | .Net Framework 3.5
Build | Target Plat from | Either X64 or Any Cpu | Save the changes

Add u r reference :
using Microsoft.SharePoint.dll;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using( SPSite  spSite = new SPSite("http://sp2010:8081") )
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    foreach (SPWeb subWeb in spWeb.Webs)
                    {
                        Console.WriteLine(subWeb.Title);
                        Console.ReadLine();
                    }
                }
            }
        }
    }
}
 

Reading a SharePoint Site title Using a console App

File | New | Project |  Visual C# |  .Net Frame Work 3.5  | Console Application
 
Give a Name there:  | Choose Location |  Click on Ok.
 
1. Add reference : Microsoft.SharePoint.dll
      from the location:
            c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll
 
2.  Right Click on Console Application Project |
From Application |           Target Framework   | .Net Framework 3.5 
             Build | Target Plat from | Either X64 or Any Cpu  | Save the changes
 
Add u r reference :
using Microsoft.SharePoint.dll;


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using( SPSite  spSite = new SPSite("http://sp2010") )
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    Console.Write(spWeb.Title);
                    Console.ReadLine();
                }
            }
        }
    }
}


 

Monday, November 12, 2012

Search Administration Content source stopping

Soluttion:

Restart office sharepoint server service from the query server / where CA is hosted (****8153).
That will resolve the issue.

Serach Administration one of the index server is erroring

Could not connect to server ****8152 for application '****_SharedServices'. This error might occur if the server is not responding to client requests, the firewall or proxy configuration is preventing the server from being contacted, or the search administration Web service is not running on the server.

Solution:


  1. Stop the Office SharePoint Services Search service. To do this, follow these steps:
    1. Click Start, click Run, type cmd , and then click OK.
    2. At the command prompt, type net stop osearch, and then press ENTER.
    3. Type exit to exit the command prompt.
  2. Download and install the IIS 6.0 Resource Kit Tools. To obtain the IIS 6.0 Resource Kit Tools, visit the following Microsoft Web site:
  3. On each server in the farm that has Office SharePoint 2007 installed, follow these steps:
    1. Click Start, click Run, type cmd , and then click OK.
    2. Navigate to the location of the IIS 6.0 Resource Kit Tools (default location is: C:\Program Files\IIS Resources\SelfSSL)
    3. At the command prompt, type selfssl /s:951338967 /v:1000, and then press ENTER. 

      Notes
      • For 64 bit Server, 951338967 is the default ID of the Office Server Web Services certificate.
      • For 32 bit Server, 1720207907 is the default ID of the Office Server Web Services certificate. You can check the ID of Office Server Web Services from IIS.
      • 1000 is the number of days that the certification will be valid.
      • You need to execute the selfssl command on each MOSS Server in the farm which is running a "Office Server Web Services" site.
      • SharePoint partly uses SSL name resolution in the background between farm servers, which users generally do not need to be aware of.
  4. Start the Office SharePoint Services Search service. To do this, follow these steps:
    1. At the command prompt, type net start osearch, and then press ENTER.
    2. Type exit to exit the command prompt.
  5. Download and install the following update to the .NET Framework 3.5 SP1. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
    959209 An update for the .NET Framework 3.5 Service Pack 1 is available

Wednesday, September 21, 2011

The detection failed, this can be due to a corrupted installation database

Recently I had to upgrade my MOSS farm with Aprils CU. So I confirmed downtime, prepared myself to patch 6 servers and during nice saturday morning, started to patch.
I have doubleclicked installation exe file downloaded from microsoft.com and after 10 seconds following message appeared:


The detection failed, this can be due to a corrupted installation database

Basicaly that means that your installed database is not in good shape and process has difficulties to read required informations from it. So patching could not continue.
As this happened on all servers in the farm, initial talks about reinstalling whole MOSS 2007 were proscribed. Because of importancy, there was no time and opportunity to play and google, MS call had to be logged.

Actually.. I was pretty much surprised how fast it was sorted out and how proffesional two engineers were.

So you have two options how to solve this. (well basicaly three - you can remove all information about MOSS with Windows Installer CleanUp Utility -
http://support.microsoft.com/kb/290301 to remove all references to MOSS, delete all folders and install it again :-) But definetelty we dont want to go with this way )

1.there are many articles about this how to solve it just with regedit.exe. They are all similar to next few words:

-------------------------------------------------------------------------------------------------------------------------
Take a backup of the products hive HKEY_CLASSES_ROOT\Installer\Products by exporting it to a file.

Microsoft Office SharePoint Server 2007
=================================
1. Rename
HKEY_CLASSES_ROOT\Installer\Products\00002109D01100000000000000F01FEC\Patches
to
HKEY_CLASSES_ROOT\Installer\Products\00002109D01100000000000000F01FEC\Patches_old

Microsoft Windows SharePoint Services 3.0
====================================
1. Rename
HKEY_CLASSES_ROOT\Installer\Products\00002109410100000000000000F01FEC\Patches
to
HKEY_CLASSES_ROOT\Installer\Products\00002109410100000000000000F01FEC\Patches_old

Run the your patch again. If this succeeds a new Patches regkey will be created.
--------------------------------------------------------------------------------------------------------------------------------------------

Well.. that might help in some cases but it didn't help me. I had seriously corrupted installers database. Somebody or something deleted files and folders directly in %windir%\installer folder. Well at least that is only RCA from MS.
If you need to solve this issue and registry magic doesn't help. Following might.


2.
a.)
Run the ROIScan.vbs that is attached to this article. It doesnt have GUI but list also non-microsoft products, what is better. You can find output in " %temp%" folder.
when you run it just by typing cscript %path to script%\roiscan.vbs it will collect all information about any software and put it in nice summary on the top of the log.

b.)
Then you should copy from some working server whole "%windir%\installer" folder to temp location on affected server or download and extract all files that are listed in the output. Best from some same configured server so you have all required files. Or you can run WiCollectFiles.vbs (attached) on every server on your environmnent. This will collect all unique files from installer folder to central location.

Use as follows:
1. Create a network share with "write" permissions "\\<Server>\Restore" on any server.
2. Run the attached script on all relevant servers to build up the structured files collection
cscript WiCollectFiles.vbs SRestoreLocation="\\<Server>\Restore"
The script will collect all unique files and you can use that share for the repair operations.
c.)
Once you have created the central restore share. You use another attached script called MspFixUp.vbs
To run the repair with MspFixUp you can use this command from the broken servers
cscript MspFixUp.vbs /L0 SRestoreLocation="\\<Server>\Restore"
This will look into all MSP /MSI files compare with informations you have on servers and rename MSP/MSI and stores them in %windir%\installer folder.

Important: "You can use L1 swich that will unregister all Office patches that could not be restored!
I dont recommend it, so i used L0 that will just restore ones that can be restored.

Note: If we run the command with the SRestoreLocation pointing to a server, the runtime of the script will be quite long!
To improve the runtime of the script you can copy the "Restore" share locally first and use

You can use ROIScript.vbs or WIPR.exe to collect informations again and see what you missing. It will actually tell you exact file names, and how they should be called, so you can extract them, download or collect any other way, then just rename them and place to Installers folder again.


That is pretty much it, it solved my problem and was not so complicated. I have tested the scripts and had confirmed from MS, that they used them for a lot of cases without any issue. I recommend to check at least header of each of them to see possible switches and options.

Source:
http://moss2007.kbnk.info/Patching/solved-the-detection-failed-this-can-be-due-to-a-corrupted-installation-database.html