SharePoint Password Recovery

Below is the powershell Script to recover SharePoint passwords.
&$env:windir\system32\inetsrv\appcmd.exe list apppool "SharePoint Central Administration v4" /text:ProcessModel.Password

Access BCS Data via C#

The below code snippet allows for access BCS data via C#

SPFarm farm = SPFarm.Local;
SPServiceProxyCollection spc = farm.ServiceProxies;
BdcServiceApplicationProxy sap = (BdcServiceApplicationProxy)(
                (from sp in spc 
                 where sp.TypeName.Equals("Business Data Connectivity Service")
                 select sp).First().ApplicationProxies.First());
DatabaseBackedMetadataCatalog catalog = sap.GetDatabaseBackedMetadataCatalog();

 IEntity ect = catalog.GetEntity("WPI.SharePoint.ITPMO.Data.BCS.Planview.ProjectData_Model", "ProjectDataEntity");
ILobSystem lob = ect.GetLobSystem();
ILobSystemInstance lobi = lob.GetLobSystemInstances()["ProjectData_Model"];
IFilterCollection filter = ect.GetDefaultFinderFilters();
IEntityInstanceEnumerator ects = ect.FindFiltered(filter, lobi);
while (ects.MoveNext())
{
Console.WriteLine(ects.Current["ProjectName"].ToString());
}

JQuery Add New Item to SPList

<div>
    <p>
        Task Title: 
        <input id="Text1" type="text" />
        <input id="Button1" type="button" value="Create Task" />
    </p>
    </div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  
<script>
    $(document).ready(function () {
        $("#newTaskButton").click(function () {
            CreateNewItem($("#newTaskTitle").val());
        });
    });


    function CreateNewItem(title) {
        var batch =
    "<Batch OnError=\"Continue\"> \
        <Method ID=\"1\" Cmd=\"New\"> \
            <Field Name=\"Title\">" + title + "</Field> \
        </Method> \
    </Batch>";

        var soapEnv =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
    <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \
        xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
        <soap:Body> \
        <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
            <listName>Tasks</listName> \
            <updates> \
            " + batch + "</updates> \
        </UpdateListItems> \
        </soap:Body> \
    </soap:Envelope>";

        var wsUrl = window.location.protocol + "//" + window.location.hostname + L_Menu_BaseUrl + "/_vti_bin/lists.asmx";
        $.ajax({
            url: wsUrl,
            beforeSend: function (xhr) {
                xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
            },
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=utf-8"
        });
    }

    function processResult(xData, status) {
        alert(status);
    }
</script>

Export HTML Table to Excel with JS

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
    <script Language="javascript">
        function TableToExcel() {
            var strCopy = document.getElementById("detailsTable").innerHTML;
            window.clipboardData.setData("Text", strCopy);
            var objExcel = new ActiveXObject("Excel.Application");
            objExcel.visible = true;

            var objWorkbook = objExcel.Workbooks.Add;
            var objWorksheet = objWorkbook.Worksheets(1);
            objWorksheet.Paste;
        }

        function exportToExcel() {
            var oExcel = new ActiveXObject("Excel.Application");
            var oBook = oExcel.Workbooks.Add;
            var oSheet = oBook.Worksheets(1);
            for (var y = 0; y < detailsTable.rows.length; y++)
            // detailsTable is the table where the content to be exported is
            {
                for (var x = 0; x < detailsTable.rows(y).cells.length; x++) {
                    oSheet.Cells(y + 1, x + 1) = detailsTable.rows(y).cells(x).innerText;
                }
            }
            oExcel.Visible = true;
            oExcel.UserControl = true;
        }
    </script>
    <title></title>
</head>
<body>
    <table id="detailsTable" border="1">
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>$100</td>
      </tr>
    </table>
    </span>
    <input id="clickExcel" type="button" value="button" onclick="javascript:TableToExcel()"/>
    <a href="javascript:exportToExcel();">Export to Excel</a><br/>
</body>
</html>

SharePoint Search Server 2010 Error

I was experiencing the below error message. While searching the internet and poking around on my SharePoint farm for a possible solution to the error i was able to find the below solution.

Error: The mount operation for the gatherer application [GUID] -crawl-0 has failed because the schema version of the search gatherer database is less than the minimum backwards compatibility schema version supported for this gatherer application. The database might not have been upgraded.

Solution: Go to the Central Admin and determine the status of the SharePoint DB's. A healthy state shows "No Action Required" for all DB's but in my case the majority of my DB's needed to be updated.
Http://[central admin]/_admin/DatabaseStatus.aspx

Finally run this command: psconfig.exe -cmd upgrade -inplace b2b -wait

Upon completion of running this command everything read "No Action required" and I was able to run the SharePoint crawl once again.

How to assign an exiting SharePoint group to a site using the SharePoint object model?

The below code demonstrates how you can assign a SharePoint Group to a SharePoint site  using the SharePoint object model.

SPSite spsite = new SPSite("Site_Name");
try
{
     using (SPWeb web = spsite.OpenWeb())
     {
          web.AllowUnsafeUpdates = true;
          SPGroup sgrp = web.SiteGroups["Group_Name"];
          SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader);
          SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)sgrp);
          roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
          web.RoleAssignments.Add(roleAssignment);
          web.Update();
     }
}
catch (Exception ex)
{
     LoggingManager.WriteEventToLogFile(ex);
}

 


 

CAML Query Utility by U2U

This is a great utility which i have used countless times to generate CAML Queries.

Enjoy....

http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx

Anonymous Access

We had a issue with Anonymous Access  in our production environment. Each time a user would go to that list information there would be prompted to login. We followed the the step below to get around it...

List Permission Settings

1.     Stsadm -o deactivatefeature -url http://site.url.name -filename ViewFormPagesLockdown\feature.xml

2.     Break the inheritance for the list

3.     Uncheck the anonymous access for the list and save

4.     Reapply the anonymous access for the list and save

5.     Stsadm -o activatefeature -url http://site.url.name -filename ViewFormPagesLockdown\feature.xml

Useful link...

http://support.microsoft.com/kb/927082/en-us?spid=11373&sid=200

Configurting BizTalk WS Adapter with ISAPI redirects work-around.

We recently encounted a problem trying to configure the BizTalk WS Adapters in our production environment and we were at a stand still until we ran into the below posted link that helped us rolling out our project to the production environment...

We received the below error message when we tried to configure the Windows sharepoint services adapter on a Load balanced Windows Server 2003 Environment.

"Error encoutered while querying virtual server state for URL: http//myserver/. Make sure the site is extended by Windows SharePoint Services. (CWssAdaCfg)"

THe below link provided a solution for us...

http://blogs.msdn.com/johnwpowell/archive/2008/08/14/error-configuring-biztalk-sharepoint-adapter-on-sharepoint-sp1.aspx

Thanks John Powell for the great post.

InfoPath: Debugging and Setting up a App.config

The below article explains how to setup a your InfoPath environment for local debugging...

http://support.microsoft.com/kb/555963