Home RSS 2.0 ATOM 1.0  CDF  
 
CodeSegment - Carlos Segura Sanz (blog)
 

imagine test your webparts without compile, imagine an VBA for sharepoint, that was what I imagined yesterday and this is here... I have desire to say Yeahhhhh

Screenshoots (better an image than thousand words)

csegScript showing code

 

csegScriptWebPart custom Properties

Show Code – Show the code with line numbers to identificate errors
Run Code – The code is executed when you applies changes
Script References – Write here the references of the project (.dll files)

If the file is in windows\system or in the assembly the path is not necesary so if you need a .dll (as Microsoft.SharePoint.dll) you need include the full path in the server, separe each reference with semicolon

Script Code – Visual Basic .NET based code, (Visual studio for applications code)

Separate lines with “\\” double backslash, internally they are replaced by carriage returns.

csegScript properties



Sample script code

This sample code shows all lists in the current site and in subsites with a link to the default list view. (the source is included in the zip file)

   1:  imports Microsoft.SharePoint
   2:  imports Microsoft.SharePoint.Utilities
   3:  imports Microsoft.SharePoint.WebPartPages
   4:  imports Microsoft.SharePoint.WebControls
   5:  imports System.Web.UI
   6:  Module Script
   7:  Public Sub Main()
   8:     Dim site As SPSite = SPControl.GetContextSite(System.Web.HttpContext.Current)   
   9:     Dim allSites As SPWebCollection = site.AllWebs
  10:     Dim subSite As SPWeb
  11:     For Each subSite In allSites
  12:        Dim allSiteLists As SPListCollection = subSite.Lists
  13:        Dim subSiteList As SPList
  14:        For Each subSiteList In  allSiteLists
  15:           output.WriteLine("<IMG SRC='"+subSiteList.ImageUrl+"'></IMG>" & " " & _
                                 SPEncode.HtmlEncode(subSite.Name) & " :: " & _
                                 "<A HREF='" + subSiteList.DefaultViewUrl & "'>" & _
                                 SPEncode.HtmlEncode(subSiteList.Title) & _
                                 "</A><BR>")
  16:        Next subSiteList
  17:     Next subSite
  18:  End Sub
  19:  End Module
 
 

Special

There is two special keys (output and _this)

output (internally is an HtmlTextWriter object) that you can use in the script code.

Sample: output.WriteLine(“Hello Sharepoint Developpers”)

_this is a reference to the webpart (internally is a WebPart object)

Sample: output.WriteLine(_this.Title) 
 

Usage in six steps….

1.- Unmark “Run Script”  and mark “Show Script Source”
2.- Put your code in the properties window, after each line put \\ instead of newline.
3.- Add your system references in the Script References, separated by semicolon (remenber the full path if they are not in assembly)
4.- Apply changes
5.- If there are errors you can view the error description, line number and line text, solve the problems and apply changes.



6.- When all is correct mark “Run Script” and VOILA….

 

Download csegScriptWebPart.zip (7,91 KB)
Friday, August 12, 2005 3:45:15 PM (Hora de verano romance, UTC+02:00)
Great
Eduard
Comments are closed.

Copyright © 2008 Carlos Segura. All rights reserved.