Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Archive for the ‘Uncategorized’ Category

Expiration Policy Timer job does not seem to run

Posted by ken zheng on December 15, 2009

http://ithinksharepoint.blogspot.com/2009/03/expiration-policy-timer-job-does-not.html

http://vspug.com/teameli/2008/10/13/record-center-information-management-policy-jobs-not-running/

Posted in Uncategorized | Leave a Comment »

Inserting line breaks into text using Rules in InfoPath

Posted by ken zheng on December 14, 2009

If you are using solution from http://blogs.msdn.com/infopath/archive/2005/03/04/385577.aspx. You need to make sure that your textbox is formatted to be able to display paragraph breaks. To do this double-click on the text box control, go to the Display tab, and check the checkbox labeled “Allow paragraph breaks”.

After this, your code should work, but if it still doesn’t try using “\n” instead of the System.Environment.Newline.

There is another way to do that.
http://www.infopathdev.com/forums/t/2013.aspx

Posted in Uncategorized | Tagged: , | Leave a Comment »

Logging levels in Sharepoint and STSADM

Posted by ken zheng on September 17, 2009

I just found on our Front End Servers where there are no trace logs under 12\LOGS. The log files are there but without any message inside.

‘This gives you the current settings
stsadm.exe -o listlogginglevels

Run this before doing any changes on a machine. It’s always good to know the original settings before making changes.

‘This set the logging to Verbose / Error.
stsadm -o setlogginglevel -tracelevel Verbose -windowslogginglevel Error

//full path
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm” -o setlogginglevel -tracelevel Verbose -windowslogginglevel Error

Posted in Uncategorized | Tagged: , | Leave a Comment »

People Search Using JQuery

Posted by ken zheng on August 3, 2009

By modifying Jan’s script, I created a People Search JQuery which allows partial search on First Name or Last Name.


<script type="text/javascript">
    // QuickSearch v0.2
    // Created by Jan Tielens, http://weblogs.asp.net/jan
    // Modified by Ken Zheng, http://littletalk.wordpress.com
    // This sample code is provided on an “as is” basis and without warranty of any kind.

    // *** Customizable parameters ***
    var quickSearchConfig = {
        delay: 500,             // time to wait before executing the query (in ms)
        minCharacters: 3,       // minimum nr of characters to enter before search
        scope: "People",     // search scope to use "All Sites"
        numberOfResults: 15,    // number of results to show
        resultsAnimation: 200,  // animation time (in ms) of the search results
        resultAnimation: 0      // animation time (in ms) of individual result (when selected)
    };    

	//Search
	function searchSubmit(){
		var query = $("#quickSearchTextBox").val();
		//window.location="/searchcenter/Pages/Results.aspx?k="+query+"&s=All%20Sites";
		window.location="/searchcenter/Pages/peopleresults.aspx?k="+query;
	}
</script>

<style type="text/css">
    .quickSearchResultDivUnselected
    {
        background: white;
        border: 1px solid white;
        margin-left: 2px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .quickSearchResultDivSelected
    {
        background: #EEEEEE;
        border: 1px solid Gray;
        margin-left: 2px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
</style>
<table id="quickSearchTable" class="ms-sbtable ms-sbtable-ex" border="0">
    <tbody>
		<th align="left">People Search</th>
		<tr class="ms-sbrow">
			<td><input type="radio" name="peoplegroup" checked="checked" value="FirstName">First Name</td>
			<td><input type="radio" name="peoplegroup" value="LastName">Last Name</td>
		</tr>
        <tr class="ms-sbrow">
            <td class="ms-sbcell" colspan=2>
                <input style="width: 100%" id="quickSearchTextBox" class="ms-sbplain" title="Enter search words"
                    style="width: 170px" alt="Enter search words" maxlength="200" value="" />
            </td>
            <td class="ms-sbgo ms-sbcell" style="width: 14px">
			  <a id="SearchArea_go" href="javascript:searchSubmit()" title="Go Search">
                <img title="Go Search" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px;
                    border-right-width: 0px" alt="Go Search" src="/_layouts/images/gosearch.gif" />
		      </a>
            </td>
            <td style="width: 1px">
            </td>
        </tr>
    </tbody>
</table>
<div id="quickSearchResults" style="display: none;">
</div>

<script type="text/javascript">
    var quickSearchTimer;
    var quickSearchSelectedDivIndex = -1;

	$('#quickSearchTextBox').click(function(){
		var div = $("#quickSearchResults");
		div.hide('fast');
		return false;
	});

    function showResultsDiv(text) {
        var div = $("#quickSearchResults");
        var prevTable = div.prev();

        var divCss = {
            "left": prevTable.offset().left,
            "padding": 2,
            "position": "absolute",
            "top": prevTable.offset().top + prevTable.height() + 1,
            "border": "1px solid #7f9db9",
            "width": prevTable.width() - 3,
            "background": "white",
            "max-width": prevTable.width() - 3
            };

        div.css(divCss).append(text).slideDown(quickSearchConfig.resultsAnimation);
    }

    $(document).ready(function() {
        $('#quickSearchTextBox').keyup(function(event) {
            var previousSelected = quickSearchSelectedDivIndex;

            // catch some keys
            switch(event.keyCode) {
                case 13:    // enter
                    var selectedDiv = $("#quickSearchResults>div:eq(" + quickSearchSelectedDivIndex + ") a");
                    if(selectedDiv.length == 1)
                        window.location = selectedDiv.attr("href");
                    break;
                case 38:    // key up
                    quickSearchSelectedDivIndex--;
                    break;
                case 40:    // key down
                    quickSearchSelectedDivIndex ++;
                    break;
            }

            // check bounds
            if(quickSearchSelectedDivIndex != previousSelected) {
                if(quickSearchSelectedDivIndex < 0)
                    quickSearchSelectedDivIndex = 0;
                if(quickSearchSelectedDivIndex >= $("#quickSearchResults>div").length -1)
                    quickSearchSelectedDivIndex = $("#quickSearchResults>div").length - 2;
            }

            // select new div, unselect the previous selected
            if(quickSearchSelectedDivIndex > -1) {
                if(quickSearchSelectedDivIndex != previousSelected) {
                    unSelectDiv( $("#quickSearchResults>div:eq(" + previousSelected + ")"));
                    selectDiv($("#quickSearchResults>div:eq(" + quickSearchSelectedDivIndex + ")"));
                }
            }

            // if the query is different from the previous one, search again
            if($('#quickSearchTextBox').data("query") != $('#quickSearchTextBox').val()) {
                if (quickSearchTimer != null) // cancel the delayed event
                    clearTimeout(quickSearchTimer);
                quickSearchTimer = setTimeout(function() { // delay the searching
                        $("#quickSearchResults").fadeOut(200, initSearch);
                    } , quickSearchConfig.delay);
            }
        });
    });

    function unSelectDiv(div) {
        // first stop all animations still in progress
        $("#quickSearchResults>div>div").stop(true,true);

        div.removeClass("quickSearchResultDivSelected").addClass("quickSearchResultDivUnselected");
        $("#details", div).hide();
    }

    function selectDiv(div) {
        div.addClass("quickSearchResultDivSelected");
        $("#details", div).slideDown(quickSearchConfig.resultAnimation);
    }

    function initSearch() {
        // first store query in data
        $('#quickSearchTextBox').data("query", $('#quickSearchTextBox').val());

        // clear the results
        $("#quickSearchResults").empty();

        // start the search
        var query = $("input[@name='peoplegroup']:checked").val() +":" +$("#quickSearchTextBox").val();
		//alert(query);
        if(query.length >= quickSearchConfig.minCharacters) {
            showResultsDiv("Searching ..."); // display status
            search(query);
        }
    }

    function search(query) {
        quickSearchSelectedDivIndex = -1;
        var queryXML =
            "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'> \
            <Query domain='QDomain'> \
             <SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats> \
             <Context> \
              <QueryText language='en-US' type='STRING' >SCOPE:\"" + quickSearchConfig.scope + "\"" + query + "</QueryText> \
             </Context> \
            <SortByProperties><SortByProperty name='Rank' direction='Descending' order='1'/></SortByProperties> \
             <Range><StartAt>1</StartAt><Count>" + quickSearchConfig.numberOfResults + "</Count></Range> \
             <EnableStemming>false</EnableStemming> \
             <TrimDuplicates>true</TrimDuplicates> \
             <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery> \
             <ImplicitAndBehavior>true</ImplicitAndBehavior> \
             <IncludeRelevanceResults>true</IncludeRelevanceResults> \
             <IncludeSpecialTermResults>true</IncludeSpecialTermResults> \
             <IncludeHighConfidenceResults>true</IncludeHighConfidenceResults> \
            </Query></QueryPacket>";

        var soapEnv =
            "<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> \
                <Query xmlns='urn:Microsoft.Search'> \
                  <queryXml>" + escapeHTML(queryXML) + "</queryXml> \
                </Query> \
              </soap:Body> \
            </soap:Envelope>";

        $.ajax({
            url: "/_vti_bin/search.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });

        function processResult(xData, status) {
            var html = "";
            $(xData.responseXML).find("QueryResult").each(function() {
                var divWidh = $("#quickSearchTable").width() - 13;

                var x = $("<xml>" + $(this).text() + "</xml>");
                x.find("Document").each(function() {
                    var title = $("Title", $(this)).text();
                    var url = $("Action>LinkUrl", $(this)).text();
                    var description = $("Description", $(this)).text()

                    html +=
                        "<div class='quickSearchResultDivUnselected' style='width:" + divWidh + "px;max-width:" + divWidh +"px'> \
                            <a href='" + url + "'>" + $("Title", $(this)).text() + "</a> \
                            <div style='display:none' id='details' style='margin-left:10px'>"
                                + description +
                                "<br/>" + url + " \
                            </div> \
                        </div>";
                });
                if(x.find("TotalAvailable").text() != "")
                    html += "<div style='text-align:right'>Total results: " + x.find("TotalAvailable").text() + "</div>";
                else
                    html += "<div style='text-align:right'>Total results: 0</div>";
            });

            $("#quickSearchResults").empty().append(html);
            $("#quickSearchResults>div>a").hover(
                function() { selectDiv($(this).parent()); },
                function() { unSelectDiv($(this).parent());  }
            );
            showResultsDiv();
        }
    }

    function escapeHTML (str) {
       return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    }
</script>

Posted in Uncategorized | 3 Comments »

jQuery Ticker for SharePoint Announcement List

Posted by ken zheng on July 23, 2009

By using Scott Price’s code, I add a query to the CAML so it will only display annoucment which not expired.

<script type="text/javascript" src="/Development Library/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="/Development Library/jquery.newsticker.js"></script>
<script type="text/javascript" src="/Development Library/DateUtilities.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
	var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
		soapEnv += "<listName>Announcements</listName>";
		soapEnv += "<query><Query><Where><Geq><FieldRef Name='Expires' /><Value Type='DateTime'><Today/></Value></Geq></Where></Query></query>";
		soapEnv += "<viewFields><ViewFields><FieldRef Name='Title'/><FieldRef Name='Created'/><FieldRef Name='ID'/></ViewFields></viewFields>"; //<RowLimit>1</RowLimit>
		soapEnv += "</GetListItems></soapenv:Body></soapenv:Envelope>";

        $.ajax({
            url: "../_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    });

function processResult(xData, status) {
        var newnews = $("<ul>").attr("class", "newsticker");
        var rows;
        if (xData.responseXML.getElementsByTagName("z:row").length==0)
        {
			var url = "/test/Lists/Announcements/";
            var liHtml = "<li class='newscontent'> <b> No Latest News <br><br><a href='" + url + "'>Read All"+"</a></b></li>";
            newnews.append(liHtml);
        }
        else
        {
			rows = xData.responseXML.getElementsByTagName("z:row");
			jQuery(rows).each(function() {
            var createdDate= $(this).attr("ows_Created").split(" ");
            var url = "/test/Lists/Announcements/DispForm.aspx?ID=" + $(this).attr("ows_ID");
            createdDate = parseDate(createdDate[0]);
            var liHtml = "<li class='newscontent'>" +  formatDate(createdDate ,'dd MMM yy')+ " - <b>" +  $(this).attr("ows_Title")+ "<br><br><a href='" + url + "'>Read Details"+"</a></b></li>";
            newnews.append(liHtml);
        });
        }

        newnews.appendTo("#tasksUL").newsTicker();
    }
</script>

<style type="text/css">
.newsticker {
list-style-type: none;
height:50px;
color:#336699;
margin-top: 10;
}

.newscontent{
list-style-type: none;
margin-left: 0;
display: inline;

}

.news{
background: url(/_layouts/1033/IMAGES/SIMCENTRAL/link_m.gif) no-repeat  scroll center top;
width:240px;
}

.marktop {
background:transparent url(/_layouts/1033/IMAGES/SIMCENTRAL/link_t.gif) no-repeat scroll center top;
height:11px;

padding:0;
width:240px;
}

.markbottom {
background:transparent url(/_layouts/1033/IMAGES/SIMCENTRAL/link_b.gif) no-repeat scroll center top;
height:11px;
margin-left:0;
padding:0;
width:240px;
}
.markcenter {
height:auto;
margin-top:10;
padding:0;
width:211px;
}
</style>
<div class="markcenter">
<div class="marktop"/>
<div class="news">
<br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Noticeboard</b>
<div id="tasksUL"
</div>
</div>
<div class="markbottom"/>
</div>

Posted in Uncategorized | Tagged: , | 1 Comment »

Cannot open log for source *. You may not have write access.

Posted by ken zheng on July 13, 2009

1. Click Start -> Run and type: regedit
2. Click Ok
3. Locate: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\ Eventlog\Application
4. Modify CustomSD to give all users read/write access to the Application event log by appending the string (A;;0×3;;;AU) to the CustomSD entry.

For example

O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0007;;;SY)(A;;0×7;;;BA) (A;;0×7;;;SO)(A;;0×3;;;IU)(A;;0×3;;;SU)(A;;0×3;;;S-1-5-3)(A;;0×3;;;AU)

The completed blog is http://mossipqueen.wordpress.com/2008/08/04/cannot-open-log-for-source-you-may-not-have-write-access/

Posted in Uncategorized | Leave a Comment »

Passed ITIL V3 Foundation exam

Posted by ken zheng on July 8, 2009

After 2 and half days course and I passed the ITIL V3 foundation exam today, no more study.

Posted in Uncategorized | Leave a Comment »

please wait while the installer finishes determining your disk space requirements

Posted by ken zheng on May 21, 2009

When I install AJAX MSI on Windows Server 2008, It pops up with the message “please wait while the installer finishes determining your disk space requirements”, and after a few hours it still told me to wait.

You can run command line to avoid the message:
msiexec /package /qr

this will run the installation with reduced UI.

Posted in Uncategorized | Leave a Comment »

Add the PDB File to the GAC

Posted by ken zheng on May 18, 2009

The PDB file needs to be in the GAC for debugging in Visual Studio. You can add this file through a feature manifest file, but you are unlikely to want to deploy the PDB to the GAC on your production server, so a better way on the dev server is to directly place files in the GAC. To do this, map a drive in windows explorer to

\\[your server name]\c$\windows\assembly

This bypasses the windows explorer shell special handling for this folder, and allows you to copy and paste files as normal without using GACUTIL.

In the GAC_MSIL subfolder, find the subfolder corresponding to the name of your assembly. Below there will be one or more version subfolders. Find the latests version subfolder., and copy your timer job dll and pdb file (built in debug mode!) to this folder.

Posted in Uncategorized | 2 Comments »

Respond to SharePoint Survey by javascript

Posted by ken zheng on May 12, 2009

After one day’s play around, I wrote this javascript which fill in the survey by parse the query string. There is a jquery function ($(‘#aspnetForm’).fadeTo(“fast”,0.33)) to fade the whole page so you can comment it out.

I only used textbox field and checkbox but you can extend the function easily.

<script>

_spBodyOnLoadFunctionNames.push("fillValues");

function fillValues() {
  //jquery to fade opacity
  $('#aspnetForm').fadeTo("fast",0.33)

  var qs = location.search.substring(1, location.search.length);
  // alert(qs);
  var args = qs.split("&");
  var vals = new Object();
  for (var i=0; i < args.length; i++) {
    var nameVal = args[i].split("=");
    var temp = unescape(nameVal[1]).split('+');
    nameVal[1] = temp.join(' ');
    vals[nameVal[0]] = nameVal[1];
    //alert(nameVal[0] + " " + nameVal[1]);
  } 

  if(setTextFromFieldName("Question1", vals["question1"]))
  {
    simulateButtonClick("diidIOSaveItem");
  }
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);

  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
    }
  }
  return null;
}

function setTextFromFieldName(fieldName, value) {
 if (value == undefined) return false;

 var theInput = getTagFromIdentifierAndTitle("input","TextField",fieldName);
 theInput.value=value
 return true;
}

//To use this function: setCheckboxFromFieldName("Checkbox", 0);
function setCheckboxFromFieldName(fieldName, value) {
 if (value == undefined) return;
   var theInput = getTagFromIdentifierAndTitle("input","BooleanField",fieldName);
theInput.checked=value;
}

function simulateButtonClick(name){
  var tags = document.getElementsByTagName("input");

  for (var i=0; i < tags.length; i++) {
   var tempString = tags[i].id;
   if(tempString.indexOf(name)>0)
   {
     tags[i].click();
    }
  }
}
</script>

Posted in Uncategorized | Leave a Comment »