Thursday, January 31, 2013

Wednesday, January 30, 2013

Friday, January 25, 2013

Error Handling and Logging in Powershell

When you run this script it will create a .csv file where you are running your script.

$URL = "siteurl"
$site = New-Object Microsoft.SharePoint.SPSite($URL)
$web = $site.openweb("")
#logging
$timestamp = get-date -format "yyyyMMdd_hhmmtt"
$filenameStart = "Log2CSVFile"
$logfile = ("{0}{1}.csv" -f $filenamestart, $timestamp)

$header = "Head1,Head2"
$header | out-file -FilePath $logfile

try  {
           
            $list=$web.Lists["User Information List"]
            $listname = $list.title
            $msg = ("{0},{1}" -f "List:", "$listname")
            $msg | out-file -FilePath $logfile  -append
            Write-Host $list.title
      }
Catch
      {
          $msg = ( "{0},{1}" -f "Error occurred while reading list..:", $_)
            $msg | out-file -FilePath $logfile  -append
      }
     
      $i++


$web.Dispose()
$site.Dispose()




Tuesday, January 8, 2013

SharePoint:DateTimeControl readonly textbox + SharePoint 2010

my date control id is "dtSummaryDate" Please change the name with your date control id.


<SharePoint:DateTimeControl Enabled="false" runat="server" ID="dtSummaryDate
" DateOnly="true" />


<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">


<script language="javascript" type="text/javascript">

        _spBodyOnLoadFunctionNames.push("ReadOnlyTexbox");

        function ReadOnlyTexbox()
        {
            var x = document.getElementsByTagName("INPUT");

            alert(x.length);

            for (var i = 0; i < x.length; i++) {
                if (x(i).id.indexOf("dtSummaryDate") > 0) {

                   // alert(x(i));
                    //x(i).disabled = 'disabled';
                    x(i).setAttribute('readonly', 'readonly');
                }
            }
         }      
       
    </script>
 </asp:Content>

Followers