Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

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()




Friday, August 3, 2012

SharePoint 2010: Custom Rss Feed for Document Library


Here is the good post for custom Rss Feed. It worked for me.


 If you are working for document library replace “LinkTitle” with Title as shown below code.

foreach (SPListItem item in items)
          {
              sb.Append("<item>");
              AddTag("title", item["Title"].ToString(), sb);
              //AddTag("link", list.RootFolder.Url + "/DispForm.aspx?ID=" + item.ID, sb);

             // AddTag("link", "http://site/News/default.aspx?itemid=" + item.ID, sb);

             AddTag("link", "http://site/news/default.aspx?itemid=" + item.ID, sb);
              //AddTag("link", listurl  + item.ID, sb);
             
              sb.Append("<description>");
             
              foreach (string viewField in view.ViewFields)
              {

                  if (viewField != "Title")
                  //if (viewField != "LinkTitle")
                  {
                      AddTag(viewField.Replace("_x0020_", " "),item.GetFormattedValue(viewField), sb);
                  }
              }
              sb.Append("</description>");
              sb.Append("</item>");
          }

Followers