Change the default scope of SharePoint calendar view to week

Actually using object model we can’t set the default scope of Calendar view. Let’s see how the SharePoint UI do it and then try to replicate the same in our solution.

When you change default scope of calendar view through UI, SharePoint sends RPC request to _vti_bin/owssvr.dll.  To see what RPC request SP sends, let’s modify the default scope through sharepoint UI and check the request in  fiddler. In fiddler you will see that Sharepoint UI sets the scope by embedding it in <CalendarViewstyle> node of view XML. If you have the fiddler open, just look for the following text in request XML. You will find that Week view style is set as True by default(see highlighted). We need to replicate the same in our RPC request.

<CalendarViewStyle Title=”Day” Type=”day” Template=”CalendarViewdayChrome” Sequence=”1″ Default=”FALSE” >
<CalendarViewStyle Title=”Week” Type=”week” Template=”CalendarViewweekChrome” Sequence=”2″ Default=”TRUE” >
<CalendarViewStyle Title=”Month” Type=”month” Template=”CalendarViewmonthChrome” Sequence=”3″ Default=”FALSE” >

Basically, this custom solution will be a two step process -

Summary

Step 1 - create an Html form for posting RPC request. On submit, this will post RPC request to _vti_bin/owssvr.dll.

Step 2 – Open the Html form in browser and submit the RPC method call to modify the calendar view.

Implementation

STEP 1

1) Create an aspx page with this code. This page can be a SharePoint application page (i.e. you can store it in ‘layouts’ folder of SP system directory)

<scripttype=”text/javascript” language =”JavaScript”>

function InsertSecurityValidation(oForm) {

var sFormDigest = ‘<SetVar Name=”__REQUESTDIGEST”>’

+ oForm.elements["__REQUESTDIGEST"].value + “</SetVar>\n”;

var oPostBody = oForm.elements["PostBody"];

var rePattern = /<\/Method>/g;

oPostBody.value = oPostBody.value.replace(rePattern,

sFormDigest + “</Method>”

);

}

</script>

<form method=”post” action=”http://[servername]/site/sitename/_vti_bin/owssvr.dll”

onsubmit=”InsertSecurityValidation(this);”>

<SharePoint:FormDigestID=”FormDigest1″runat=”server” />

<input type=”hidden”name=”Cmd”value=”DisplayPost” />

<textarea rows=”18″name=”PostBody”cols=”72″></textarea>

<input type=”submit”value=”Submit” />

<input type=”reset”value=”Reset” />

</form>

 STEP 2

Open this aspx page in browser. This will display the Html form we created in Step 1. Simply copy and paste the following block of RPC method code in the textbox and click submit. This will modify the calendar view of this list by setting its scope to ‘week’.

<?xmlversion=1.0encoding=utf-8?>

<Method ID=UpdateView>

<SetVar Name=Cmd>UpdateView</SetVar>

<SetList Scope=Request>ListGUID</SetList>

<SetVar Name=View>{ViewGuid}</SetVar>

<SetVar Name=ViewType>CALENDAR</SetVar>

<SetVar Name=InlineEdit></SetVar>

<SetVar Name=TabularView></SetVar>

<SetVar Name=LocalizedTodayString>[Today]</SetVar>

<SetVar Name=LocalizedMeString>[Me]</SetVar>

<SetVar Name=ListVersion>4</SetVar>

<SetVar Name=ViewFPModified>FALSE</SetVar>

<SetVar Name=ReadOnly>FALSE</SetVar>

<SetVar Name=Level>1</SetVar>

<SetVar Name=NextUsing>

http://servername/site/sitename/Lists/Calendar/calendar.aspx </SetVar>

<SetVar Name=HiddenFilter></SetVar>

<SetVar Name=BaseViewID>2</SetVar>

<SetVar Name=CalViewStyles>

&lt;CalendarViewStyle Title=&quot;Day&quot; Type=&quot;day&quot; Template=&quot;CalendarViewdayChrome&quot; Sequence=&quot;1&quot; Default=&quot;FALSE&quot; /&gt;

&lt;CalendarViewStyle Title=&quot;Week&quot; Type=&quot;week&quot; Template=&quot;CalendarViewweekChrome&quot; Sequence=&quot;2&quot; Default=&quot;TRUE&quot; /&gt;

&lt;CalendarViewStyle Title=&quot;Month&quot; Type=&quot;month&quot; Template=&quot;CalendarViewmonthChrome&quot; Sequence=&quot;3&quot; Default=&quot;FALSE&quot; /&gt;

</SetVar>

<SetVar Name=HdnMethodName></SetVar>

<SetVar Name=HdnFilterNameControlIDs></SetVar>

<SetVar Name=HdnFilterValControlIDs></SetVar>

<SetVar Name=NewViewName>Calendar</SetVar>

<SetVar Name=NewViewFileName>calendar</SetVar>

<SetVar Name=Personal>FALSE</SetVar>

<SetVar Name=ViewOrder0>1_EventDate</SetVar>

<SetVar Name=ViewOrder1>2_EndDate</SetVar>

<SetVar Name=CalendarMonthTitle>fRecurrence</SetVar>

<SetVar Name=CalendarWeekTitle>fRecurrence</SetVar>

<SetVar Name=CalendarWeekLocation>Location</SetVar>

<SetVar Name=CalendarDayTitle>Title</SetVar>

<SetVar Name=CalendarDayLocation>Location</SetVar>

<SetVar Name=CalendarViewStyle>1</SetVar>

<SetVar Name=OverrideOrderBy>FALSE</SetVar>

<SetVar Name=IsThereAQuery>FALSE</SetVar>

<SetVar Name=FieldPicker1>None</SetVar>

<SetVar Name=OperatorPicker1>Eq</SetVar>

<SetVar Name=CompareWithValue1></SetVar>

<SetVar Name=OWS:CompareWithValue1:Local></SetVar>

<SetVar Name=NextIsAnd1>FALSE</SetVar>

<SetVar Name=FieldPicker2>None</SetVar>

<SetVar Name=OperatorPicker2>Eq</SetVar>

<SetVar Name=CompareWithValue2></SetVar>

<SetVar Name=OWS:CompareWithValue2:Local></SetVar>

<SetVar Name=NextIsAnd2>FALSE</SetVar>

<SetVarName=FieldPicker3>None</SetVar>

<SetVar Name=OperatorPicker3>Eq</SetVar>

<SetVar Name=CompareWithValue3></SetVar>

<SetVar Name=OWS:CompareWithValue3:Local></SetVar>

<SetVar Name=NextIsAnd3>FALSE</SetVar>

<SetVar Name=FieldPicker4>None</SetVar>

<SetVar Name=OperatorPicker4>Eq</SetVar>

<SetVar Name=CompareWithValue4></SetVar>

<SetVar Name=OWS:CompareWithValue4:Local></SetVar>

<SetVar Name=NextIsAnd4>FALSE</SetVar>

<SetVar Name=FieldPicker5>None</SetVar>

<SetVar Name=OperatorPicker5>Eq</SetVar>

<SetVar Name=CompareWithValue5></SetVar>

<SetVar Name=OWS:CompareWithValue5:Local></SetVar>

<SetVar Name=NextIsAnd5>FALSE</SetVar>

<SetVar Name=FieldPicker6>None</SetVar>

<SetVar Name=OperatorPicker6>Eq</SetVar>

<SetVar Name=CompareWithValue6></SetVar>

<SetVar Name=OWS:CompareWithValue6:Local></SetVar>

<SetVar Name=NextIsAnd6>FALSE</SetVar>

<SetVar Name=FieldPicker7>None</SetVar>

<SetVar Name=OperatorPicker7>Eq</SetVar>

<SetVar Name=CompareWithValue7></SetVar>

<SetVar Name=OWS:CompareWithValue7:Local></SetVar>

<SetVar Name=NextIsAnd7>FALSE</SetVar>

<SetVar Name=FieldPicker8>None</SetVar>

<SetVar Name=OperatorPicker8>Eq</SetVar>

<SetVar Name=CompareWithValue8></SetVar>

<SetVar Name=OWS:CompareWithValue8:Local></SetVar>

<SetVar Name=NextIsAnd8>FALSE</SetVar>

<SetVar Name=FieldPicker9>None</SetVar>

<SetVar Name=OperatorPicker9>Eq</SetVar>

<SetVar Name=CompareWithValue9></SetVar>

<SetVar Name=OWS:CompareWithValue9:Local></SetVar>

<SetVar Name=NextIsAnd9>FALSE</SetVar>

<SetVar Name=FieldPicker10>None</SetVar>

<SetVar Name=OperatorPicker10>Eq</SetVar>

<SetVar Name=CompareWithValue10></SetVar>

<SetVar Name=OWS:CompareWithValue10:Local></SetVar>

<SetVar Name=Recursive>TRUE</SetVar>

<SetVar Name=RowLimit>30</SetVar>

<SetVar Name=MobileView>TRUE</SetVar>

<SetVar Name=MobileDefaultView>TRUE</SetVar>

<SetVar Name=MobileItemLimit>3</SetVar>

<SetVar Name=__spText1></SetVar>

<SetVar Name=__spText2></SetVar>

</Method>

Useful Links
To learn how to post Sharepoint foundation RPC methods, follow this Link.

Sharepoint foundation RPC methods – http://msdn.microsoft.com/en-us/library/ms480784(v=office.14).aspx

—————————————————————————————————————————————————

Trackbacks

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>