Category Archives: sharepoint

How to create a custom Index Server search page by using ASP in SharePoint Designer 2007

INTRODUCTION

loadTOCNode(1, ‘summary’); This step-by-step article describes how to create a custom Index Server search page by using Active Server Pages (ASP) in Microsoft Office SharePoint Designer 2007.

Back to the top

MORE INFORMATION

loadTOCNode(1, ‘moreinformation’); To create a custom Index Server search page by using ASP in SharePoint Designer 2007, follow these steps.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Back to the top

Step 1: Prepare to use the ASP features in SharePoint Designer 2007

loadTOCNode(2, ‘moreinformation’); Before you can use the ASP features in SharePoint Designer 2007, you must install the components that are listed in the following Microsoft Knowledge Base article:

318287 (http://www.kbAlertz.com/Feedback.aspx?kbNumber=318287/) What you need to use Active Server Pages (ASP) in FrontPage 2002

Back to the top

Step 2: Add a form page in SharePoint Designer 2007

loadTOCNode(2, ‘moreinformation’); To do this, follow these steps:

1.

Start SharePoint Designer 2007, and then open the Web site.

2.

Click the New Document button on the toolbar.

3.

At the bottom of the document, click Design to switch to the Design view.

4.

In the Toolbox, expand Form Controls, and then double-click Form.

5.

In the Toolbox, expand Form Controls, and then double-click Input (Text).

6.

Double-click the text box that you added in step 5.

7.

In the Text Box Properties dialog box, type QUERYTEXT in the Name text box.

8.

In the Initial value box, type <%=Request(“QUERYTEXT”)%>, and then click OK.

9.

In the Toolbox, expand Form Controls, and then double-click Drop-Down Box.

10.

Double-click the drop-down box.

11.

In the Drop Down Box Properties dialog box, type QUERYFIELD in the Name text box.

12.

Click Add, and then type DocAppName in the Choice text box.

13.

Click to clear the Specify Value check box, and then click OK.

14.

Repeat steps 12 and 13 to add the following menu items:

Characterization

FileName

DocAuthor

DocTitle

15.

Click OK to close the Drop Down Box Properties dialog box.

16.

In the Toolbox, expand Form Controls, and then double-click Input (Submit).

17.

Right-click Input (Submit), and then click Form Properties.

18.

Click Send to other, and then click Options.

19.

In the Action text box, type <%=Request.ServerVariables(“URL”)%>, and then click OK two times.

20.

On the File menu, click Save.

21.

In the File name text box, type IndexServerTest.asp, and then click Save.

Back to the top

Step 3: Add the sample ASP code to the page

loadTOCNode(2, ‘moreinformation’); Note You may receive an error message if you copy the script examples directly from this article and then paste them into SharePoint Designer 2007. SharePoint Designer 2007 may misinterpret the angle brackets (< and >). To work around this behavior, copy the script and then paste it into a blank Notepad document. Then, copy the script from Notepad, and then paste it into SharePoint Designer 2007.

To add the sample ASP code to the page, follow these steps:

1.

At the bottom of the document, click Code to switch to HTML view.

2.

Type or paste the following code before the opening HTML tag.

<%

  ‘ Force variable declaration.

  Option Explicit

 

  ‘ Declare all our variables.

  Dim strQueryText

  Dim strQueryField

  Dim strSQL

  Dim strName

  Dim strValue

  Dim objRS

  Dim objField

 

  ‘ This is the list of Index Server variables that will appear.

  ‘ You can customize the list of fields. For more information,

  ‘ see Microsoft Knowledge Base article 318387.

  Const strDisplayFields = “Rank, DocAuthor, DocAppName, DocTitle, FileName, Create, Access, Characterization, VPath”

 

  ‘ This is the default Index Server catalog for all Web content.

  ‘ For information about how to customize this, see Microsoft

  ‘ Knowledge Base article 318387.

 

  Const strDataSource = “WEB”

 

  ‘ Get the value of the user-submitted search query.

  strQueryText = Request(“QUERYTEXT”)

  ‘ Set a default value if the user has not submitted anything.

  If Len(strQueryText) = 0 Then strQueryText = “%%”

 

  ‘ Get the field that the user wants to query against.

  strQueryField = Request(“QUERYFIELD”)

  ‘ Set a default value if the user has not specified a field.

  If Len(strQueryField) = 0 Then strQueryField = “DocTitle”

%>

3.

Type or paste the following code after the closing tag.

<%

‘ Check if the user has entered a value in the form

If strQueryText <> “%%” Then

 

  ‘ Build the SQL statement from the user-specified options.

  strSQL = “SELECT ” & strDisplayFields & ” FROM SCOPE() ” & _

     “WHERE ((” & strQueryField & ” LIKE ‘%” & strQueryText & “%’) AND ” & _

     “((VPath NOT LIKE ‘%/_vti%’) AND (VPath NOT LIKE ‘%/_private%’)))”

 

  ‘ Create a recordset object.

  Set objRS = Server.CreateObject(“ADODB.Recordset”)

 

  ‘ Open the recordset by using the SQL string with the Index Server provider.

  objRS.Open strSQL,”PROVIDER=MSIDXS;DATA SOURCE=” & strDataSource

 

  ‘ Are there any records to show?

  If objRS.EOF Then

 

    ‘ Show a default message if nothing is found.

    Response.Write “No Documents were Found.” & vbCrLf 

 

  ‘ Otherwise…

  Else

 

    ‘ Start a table.

    Response.Write “<table border=””1″”>” & vbCrLf

 

    ‘ Start the row for the header section.

    Response.Write “<tr>” & vbCrLf

    ‘ Loop through the fields collection.

    For Each objField in objRS.Fields

      ‘ Get the field’s name.

      strName  = objField.Name

      ‘ If the field has a name, escape it for HTML.

      If Len(strName)  > 0 Then strName = Server.HTMLEncode(strName)

      ‘ Output the field name as a table header.

      Response.Write “<th>” & strName & “</th>” & vbCrLf

    Next

    ‘ End the row for the header section.

    Response.Write “</tr>” & vbCrLf  

 

    ‘ Loop through all the records.

    While Not objRS.EOF

      ‘ Start a row in the data section.

      Response.Write “<tr>” & vbCrLf

      ‘ Loop through the fields collection.

      For Each objField in objRS.Fields

        ‘ Get the field’s value.

        strValue = objField.Value

        ‘ Look for null values.

        If Len(strValue) > 0 Then

          ‘ If the value is not null, escape it for HTML.

          strValue = Server.HTMLEncode(strValue)

        Else

          ‘ Otherwise, make it a non-breaking space character.

          strValue = “ ”

        End If

      ‘ Output the field value as table data.

        Response.Write “<td>” & strValue & “</td>” & vbCrLf

      Next

      ‘ End a row in the data section.

      Response.Write “</tr>” & vbCrLf

      ‘ Move on to the next record.

      objRS.MoveNext

     Wend

     Response.Write “</table>” & vbCrLf

  End If

 

Else

‘ User has not entered any value in search form

    Response.Write “Please enter a Search Term before submitting the form” & vbCrLf

End if%>

4.

On the File menu, click Save.

Back to the top

Step 4: Test the sample ASP page

loadTOCNode(2, ‘moreinformation’); 1.

Start SharePoint Designer 2007, and then open the IndexServerTest.asp page.

2.

On the File menu, point to Preview in Browser, and then click the browser that you want to use.

3.

In the text box, type your search criteria.

4.

In the list, click the field that you want to query.

5.

Click Submit.

6.

Any results that match your query appear in a table on the page.

Back to the top

Step 5: Customize the sample ASP page

loadTOCNode(2, ‘moreinformation’); The two customization options are as follows:

Change the catalog

Modify the Field list

Change the catalog

loadTOCNode(3, ‘moreinformation’); If multiple Index Server catalogs are defined on the Web server, you can specify that the sample page use a different catalog. To do this, follow these steps:

1.

Start SharePoint Designer 2007, and then open the sample Web page that you created earlier.

2.

Click Code to switch to HTML view.

3.

Locate the following line of code.

Const strDataSource = “WEB”

4.

Change the value of strDataSource to the name of your catalog so that the code resembles the following code:

Const strDataSource = My_Custom_Catalog

5.

On the File menu, click Save, and then close the file.

Modify the “Field” list

loadTOCNode(3, ‘moreinformation’); 1.

Start SharePoint Designer 2007, and then open the sample Web page that you created earlier.

2.

Click Code to switch to HTML view.

3.

Locate the line of code that resembles the following code.

Const strDisplayFields = “Rank, DocAuthor, DocAppName”

4.

Change the list of values. Separate each field name with a comma so that the line resembles the following line:

Const strDisplayFields = “Rank, DocAuthor, DocAppName, DocTitle”

5.

On the File menu, click Save, and then close the file.

The following table lists the values that you can use for the strDisplayFields variable.

Field Name

Field Type

Description

Access

Date/Time

This value indicates the last time that the file was accessed.

Characterization

Text/String

This value indicates the characterization, or the abstract, of the document. This value is computed by the Index Server.

Create

Date/Time

This value indicates the time that the file was created.

Directory

Text/String

This value indicates the physical path of the file. This path excludes the file name.

DocAppName

Text/String

This value indicates the name of the application that created the file.

DocAuthor

Text/String

This value indicates the author of the document.

DocByteCount

Numeric

This value indicates the number of bytes in the document.

DocCategory

Text/String

This value indicates the type of document, such as a memo, a schedule, or a white paper.

DocChar

Count Numeric

This value indicates the number of characters in the document.

DocComments

Text/String

This value indicates comments about the document.

DocCompany

Text/String

This value indicates the name of the company for which the document was written.

DocCreatedTm

Date/Time

This value indicates the time that the document was created.

DocEditTime

Date/Time

This value indicates the total time that was spent editing the document.

DocHiddenCount

Numeric

This value indicates the number of hidden slides in a Microsoft PowerPoint presentation.

DocKeywords

Text/String

This value indicates the document keywords.

DocLastAuthor

Text/String

This value indicates the user who edited the document most recently.

DocLastPrinted

Date/Time

This value indicates the time that the document was last printed.

DocLastSavedTm

Date/Time

This value indicates the time that the document was last saved.

DocLineCount

Numeric

This value indicates the number of lines in a document.

DocManager

Text/String

This value indicates the name of the manager of the document’s author.

DocNoteCount

Numeric

This value indicates the number of pages that have notes in a PowerPoint presentation.

DocPageCount

Numeric

This value indicates the number of pages in the document.

DocParaCount

Numeric

This value indicates the number of paragraphs in the document.

DocPartTitles

Text/String

This value indicates the names of document parts. For example, in Microsoft Excel, a spreadsheet is a document part. In PowerPoint, a slide is a document part. In Word, the file names of the documents that are contained in a master document are document parts.

DocPresentationTarget

Text/String

This value indicates the target format for a PowerPoint presentation. These formats include 35 mm, printer, or video.

DocRevNumber

Text/String

This value indicates the current version number of a document.

DocSlideCount

Numeric

This value indicates the number of slides in a PowerPoint presentation.

DocSubject

Text/String

This value indicates the subject of the document.

DocTemplate

Text/String

This value indicates the name of the template for the document.

DocTitle

Text/String

This value indicates the title of document.

DocWordCount

Numeric

This value indicates the number of words in the document.

FileIndex

Numeric

This value indicates the unique ID of the file.

FileName

Text/String

This value indicates the name of the file.

HitCount

Numeric

This value indicates the number of hits (words that match a query) in the file.

Path

Text/String

This value indicates the full physical path of the file. This path includes the file name.

Rank

Numeric

This value indicates the rank of a row. The rank ranges from 0 to 1000. Larger numbers indicate better matches.

ShortFileName

Text/String

This value indicates the short (8.3) file name.

Size

Numeric

This value indicates the size of the file, in bytes.

VPath

Text/String

This value indicates the full virtual path of the file. This path includes the file name. If there is more than one possible path, the best match for the specific query is chosen.

Write

Date/Time

This value indicates the last time that the file was written.

Back to the top

Troubleshooting

loadTOCNode(2, ‘moreinformation’);

If the Index Service is not running, you receive the following error message:

Microsoft OLE DB Provider for Indexing Service error ‘80041820’
Service is not running.
/IndexServerTest.asp, line 44

To resolve this issue, start the Index Service.

If you specify a catalog that is not valid, you receive an error message that resembles the following error message:

Microsoft OLE DB Provider for Indexing Service error ‘8004181d’
There is no catalog.
/IndexServerTest.asp, line 44

To resolve this issue, check the value of the strDataSource variable. If the value is correct, restart the Index Service.

Back to the top

REFERENCES

loadTOCNode(1, ‘references’); For more information about how to work with the Microsoft Windows 2000 Indexing Service, click the following article number to view the article in the Microsoft Knowledge Base:

185985 (http://www.kbAlertz.com/Feedback.aspx?kbNumber=185985/) Using Index Server to query and display META TAG information

256276 (http://www.kbAlertz.com/Feedback.aspx?kbNumber=256276/) Error message: “There is no catalog”

229282 (http://www.kbAlertz.com/Feedback.aspx?kbNumber=229282/) ASP code is visible when you view source of an Index Server results page

 

Understanding the SharePoint calendar and how to export it to iCal format


Understanding the SharePoint calendar and how to export it to iCal format

Introduction


One of the challenges of accessing SharePoint calendars via the object model is
that there are so many different types of events – normal events, all-day
events, recurring events, recurrence exceptions, and deleted instances – and
they all look more or less the same! 
In this post, I will shed some light on how to work with calendar events,
describe the subtleties of recurrences, and put that knowledge to work exporting
events to the

RFC 2445 iCalendar
format.


First, before we can do anything with a Calendar list, we need a way to
distinguish between different event types.

Distinguishing
between calendar item types


Calendar items in SharePoint fall into several categories. 
Single events are those which don’t repeat and only appear once on the
calendar, while recurring events may show up any number of times depending on
the recurrence pattern selected by a user. 
Either type of event may have a defined start and end time, or it may be
an all-day event which lasts from midnight to 11:59 PM.


Furthermore, individual instances of a recurring event may be deleted or edited,
creating a new event which takes its place. 
The event created by a deleted instance instructs the calendar not to
render that day’s instance of the recurring event.


Calendar events can be distinguished by looking at the fRecurrence, fAllDayEvent,
and EventType field values:



Type



Description



fRecurrence



fAllDayEvent



EventType


Single event

An
event created with the All Day Event and Recurrence checkboxes
unselected.

False

False

0


All-day event

An
event created with the All Day Event checkbox selected.

False

True

0


Recurring event

An
event created with the Recurrence checkbox selected. 
Has a recurrence icon in the All Events view. 
Appears as a single master event on the All Events view, but as
recurring instances on the Current Events and Calendar views.

True

False

1


Recurring all-day event

Same as
above, but with the All Day Event checkbox selected at creation time.

True

True

1


Recurrence exception

Created
by editing an instance of a recurring event. 
Has a strikethrough recurrence icon in the All Events view.

True

False

4


All-day recurrence exception

Same as
above, but created by editing an instance of an all-day recurring event.

True

True

4


Deleted instance of a recurring event

Created
by deleting a instance of a recurring event. 
Title is prefixed with “Deleted:” in the All Events view, and is
hidden in the Current Events and Calendar views.

True

False

3


Deleted instance of an all-day recurring event

Same as
above, but created by deleting an instance of an all-day recurring
event.

True

True

3

Understanding
recurring events


Recurring events have a number of subtleties not found in single events. 
Most importantly, one recurring event item expands into any number of
recurring event instances when it is rendered in the calendar view. 
Recurring events also make use of fields left empty in single events.


Certain fields are interpreted differently depending on whether the item in
question is a recurring event or a single event:



Field



Value for single event



Value for recurring event


EventDate

Start
date and time

Start
date and time set for the recurring event when it was created, which may
be an earlier date than the first instance of the recurring event.


EndDate

End
date and time

End
date and time for the last instance of the recurring event. 
For recurring events with no end date, this is a computed date
several years in the future.


Duration

The
time in seconds between EventDate and EndDate. 

The
duration in seconds of an individual instance of the recurring event.


 


Similarly, exceptions and deleted instances have fields which relate the event
back to the parent recurring event:



Field



Value for exception or deleted instance


MasterSeriesItemID

The ID
of the recurring event from which this exception or deleted instance was
made.


RecurrenceID

The
date and time of the instance of the recurring event which this
exception or deleted instance takes the place of.


 


Once you’ve determined that you’re working with a recurring event, you’ll likely
want to work with individual instances of the recurrence.

Recurrence
patterns and expanding events


Recurring events store the pattern used to display instances of the recurring
event as XML in the RecurrenceData field. 
While this data is best used in a read-only fashion, the following are
examples of the patterns you may encounter:



Recurrence type



RecurrenceData field value


Daily every 1 days, no end date


<recurrence><rule>

<firstDayOfWeek>su</firstDayOfWeek>


<repeat><daily dayFrequency="1" /></repeat>

<repeatForever>FALSE</repeatForever>


</rule></recurrence>


Weekly every Monday, Tuesday, and Wednesday, end by 5/31/2007


<recurrence><rule>

<firstDayOfWeek>su</firstDayOfWeek>


<repeat><weekly mo="TRUE" tu="TRUE" we="TRUE" weekFrequency="1"
/></repeat>

<windowEnd>2007-05-31T22:00:00Z</windowEnd>


</rule></recurrence>


Monthly the third Wednesday of every 2 months, no end date


<recurrence><rule>

<firstDayOfWeek>su</firstDayOfWeek>


<repeat><monthlyByDay we="TRUE" weekdayOfMonth="third" monthFrequency="2"
/></repeat>

<repeatForever>FALSE</repeatForever>


</rule></recurrence>


Yearly every May 18, end after 10 instances


<recurrence><rule>

<firstDayOfWeek>su</firstDayOfWeek>


<repeat><yearly yearFrequency="1" month="5" day="18" /></repeat>

<repeatInstances>10</repeatInstances>


</rule></recurrence>


 


Thankfully, you don’t need to parse this XML yourself to get the actual
instances of the recurring event. 
Instead, you can use the SharePoint object model to expand recurring events
during a given month:


// Get the Events list


SPSite

site = new SPSite("http://localhost&quot;);


SPWeb

web = site.RootWeb;


SPList

calendarList = web.Lists["Calendar"];


 


// Construct a query that expands recurring events


SPQuery

query = new
SPQuery
();


query.ExpandRecurrence = true;


query.Query = "<Where><DateRangesOverlap><FieldRef
Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\"
/><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where>"
;


 


// Look forward from the beginning of the current month


query.CalendarDate = new
DateTime(DateTime.Now.Year,
DateTime.Now.Month, 1);


 


// Returns all items (including recurrence instances) that


// would appear in the calendar view for the current month


SPListItemCollection

calendarItems = calendarList.GetItems(query);


 


foreach

(SPListItem item
in
calendarItems)


{


Console
.WriteLine(item["Title"]
+ ": starts "


+ item["EventDate"].ToString() +
" and ends "


+ item["EndDate"].ToString());


}


Note that after expansion, each instance of a recurring event has the same ID as
the recurring event that produced it. 
In other words, a recurring event with ID 7 will appear as many recurring
event instances in the code above, each with an ID of 7.

Putting it to
work


It’s always easier to learn from an example than from dry technical
descriptions, and to that end I’ve developed a SharePoint Solution which uses
the functionality I’ve described above. 
When installed and activated, it adds an “Export Calendar to iCal Format”
button to the Actions menu of every Calendar list in the site collection as
pictured below.


To convert events to RFC 2445 iCalendar format, I loop through each event,
translating recurrence patterns into iCalendar format and associating exceptions
and deleted instances with the recurring event they came from. 
The majority of the code deals with interpreting the recurrence pattern;
however, there is also a significant amount of code to translate SharePoint
timezone information as well.


You can download the iCalendar Exporter solution and source code, which have
been released as part of the Community Kit for SharePoint, right here. 
Launch Visual Studio, take a look at my source code, and have fun
developing custom solutions with the SharePoint calendar! Please leave a comment
if you have any questions or want to showcase an innovative solution that you've
built.

.postsub h2{
font-size: 1.4em;
margin: 0px;
padding: 5px 0em 10px;}

.post h2{
font-size: 1.2em;
margin: 0px;
padding: 0em 0em 0.5em;}

h2 {
margin-top : 10px;
font-size : 1em;}

.postsub a{
font-weight: bold;
}

a:link {
text-decoration: none;
color: #006bad;}

a:link {
text-decoration: none;
color: #006bad;}

h1 {
margin : 0px;
font-size : 1.5em;}

p {
margin : 10px 0px;}

.postsub img{
padding: 5px 5px 5px 0px;
margin: 5px 5px 5px 0px;}

.post img{
padding: 5px 5px 5px 0px;
margin: 5px 5px 5px 0px;}