Wednesday, 29 February 2012

Replace to HTML










Monday, 27 February 2012

Load a List Table dynamically with columns

This took me a while to figure out, for predefined fields like ID, Modified, Created, Title, it will still have a Hidden=True even though it is not shown in AllItems.aspx. Thus I have to check it by using the Exists method.


public void loadHeaderActionTable()
{
SPWeb web = SPContext.Current.Web;
SPList actionList = web.Lists[ActionListName];
SPListItemCollection actions = actionList.GetItems(myActionListView);

TableRow header = new TableRow();
foreach (SPField fItem in actions.Fields)
{

if (!fItem.Hidden
&& myActionListView.ViewFields.Exists(fItem.InternalName))
{

TableCell cItem = new TableCell();
cItem.Text = fItem.Title.ToString();
cItem.CssClass = "ms-vh-div";
header.Cells.Add(cItem);
myActionColumnTitle.Add(cItem.Text);

}
}
tblACList.Rows.Add(header);

}

Friday, 24 February 2012

Working List Defination

Elements.xml


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{9814D5C4-1A49-42A7-8229-06288E2E4C3F}" Name="ActionID" Type="Text" DisplayName="ActionID" Required="TRUE"></Field>
<Field ID="{271C7377-6800-4CD8-8120-D794BA90B023}" Name="Title" Type="Text" DisplayName="Title" Required="TRUE"></Field>
<Field ID="{FAE223E3-D53F-4886-9021-286C96728696}" Name="AssignedTo" Type="UserMulti" DisplayName="Resp" Required="False"></Field>
<Field ID="{A31215AF-BCD1-401D-899F-F6B2A7F77AAD}" Name="InitiatedDate" Type="DateTime" Format="DateOnly" DisplayName="InitiatedDate" Required="TRUE">
<Default>[today]</Default>
</Field>
<Field ID="{CFEE2340-8D7F-4BE9-8FE7-15DA5A255B50}" Name="TargetDate" Type="DateTime" Format="DateOnly" DisplayName="TargetDate" Required="FALSE">
<Default></Default>
</Field>
<Field ID="{E40F6006-2A64-43B9-B11F-BADD96C1ECCE}" Name="ClosedDate" Type="DateTime" Format="DateOnly" DisplayName="ClosedDate" Required="FALSE">
<Default></Default>
</Field>
<Field ID="{50B78056-F0B3-4B5B-B71F-DABD97E8D49F}" Name="Comments" Type="Note" DisplayName="Comments" Required="FALSE" NumLines="5"></Field>
<Field ID="{21D31AC1-2959-4794-84F5-C5C2CC48D06D}" Name="SubjectID" Type="Lookup" DisplayName="SubjectID" List="Lists/SubjectList" ShowField="SubjectID" Required="TRUE"></Field>

<ContentType
ID="0x0100A5D7A562B9B440FEBA25E181C4A3A098"
Name="ActionList"
Group="Action Content Type"
Description="Action List"
Version="0">
<FieldRefs>
<FieldRef ID="{9814D5C4-1A49-42A7-8229-06288E2E4C3F}" />
<FieldRef ID="{271C7377-6800-4CD8-8120-D794BA90B023}" />
<FieldRef ID="{FAE223E3-D53F-4886-9021-286C96728696}" />
<FieldRef ID="{A31215AF-BCD1-401D-899F-F6B2A7F77AAD}" />
<FieldRef ID="{CFEE2340-8D7F-4BE9-8FE7-15DA5A255B50}" />
<FieldRef ID="{E40F6006-2A64-43B9-B11F-BADD96C1ECCE}" />
<FieldRef ID="{50B78056-F0B3-4B5B-B71F-DABD97E8D49F}" />
<FieldRef ID="{21D31AC1-2959-4794-84F5-C5C2CC48D06D}" />
</FieldRefs>
</ContentType>

<!-- Do not change the value of the Name attribute below.
If it does not match the folder name of the List Definition
project item, an error will occur when the project is run. -->
<ListTemplate
Name="ListDefinition1"
Type="10001"
AllowDeletion="TRUE"
DisallowContentTypes="FALSE"
BaseType="0"
OnQuickLaunch="FALSE"
SecurityBits="11"
Sequence="410"
DisplayName="ActionList"
Description="My Action List Definition"
Image="/_layouts/images/itgen.gif"/>
</Elements>


Schema.xml



<?xml version="1.0" encoding="utf-8"?>
<List EnableContentTypes="TRUE" xmlns:ows="Microsoft SharePoint" Title="ActionList" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/ActionList-ListDefinition1" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<ContentTypes>
<ContentTypeRef ID="0x0100A5D7A562B9B440FEBA25E181C4A3A098" />
<ContentTypeRef ID="0x01">
<Folder TargetName="Item" />
</ContentTypeRef>
<ContentTypeRef ID="0x0120" />
</ContentTypes>

<Fields>
<Field ID="{9814D5C4-1A49-42A7-8229-06288E2E4C3F}" Name="ActionID" Type="Text" DisplayName="ActionID" Required="TRUE" ></Field>
<Field ID="{271C7377-6800-4CD8-8120-D794BA90B023}" Name="Title" Type="Text" DisplayName="Title" Required="TRUE"></Field>
<Field ID="{FAE223E3-D53F-4886-9021-286C96728696}" Name="AssignedTo" Type="UserMulti" DisplayName="Resp" Required="False"></Field>
<Field ID="{A31215AF-BCD1-401D-899F-F6B2A7F77AAD}" Name="InitiatedDate" Type="DateTime" Format="DateOnly" DisplayName="Initiated Date" Required="TRUE">
<Default>[today]</Default>
</Field>
<Field ID="{CFEE2340-8D7F-4BE9-8FE7-15DA5A255B50}" Name="TargetDate" Type="DateTime" Format="DateOnly" DisplayName="TargetDate" Required="FALSE">
<Default></Default>
</Field>
<Field ID="{E40F6006-2A64-43B9-B11F-BADD96C1ECCE}" Name="ClosedDate" Type="DateTime" Format="DateOnly" DisplayName="ClosedDate" Required="FALSE">
<Default></Default>
</Field>
<Field ID="{50B78056-F0B3-4B5B-B71F-DABD97E8D49F}" Name="Comments" Type="Note" DisplayName="Comments" Required="FALSE" NumLines="5"></Field>
<Field ID="{21D31AC1-2959-4794-84F5-C5C2CC48D06D}" Name="SubjectID" Type="Lookup" DisplayName="SubjectID" List="Lists/SubjectList" ShowField="SubjectID" Required="TRUE"></Field>

</Fields>
<Views>
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitleNoMenu"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
</ParameterBindings>
</View>
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="ActionID"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="AssignedTo"></FieldRef>
<FieldRef Name="InitiatedDate"></FieldRef>
<FieldRef Name="TargetDate"></FieldRef>
<FieldRef Name="ClosedDate"></FieldRef>
<FieldRef Name="Comments"></FieldRef>
<FieldRef Name="SubjectID"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="ID"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
</View>
</Views>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>


ListInstance's Element.xml


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="ActionList"
OnQuickLaunch="TRUE"
TemplateType="10001"
Url="Lists/ActionList"
Description="My List Instance">
<Data>
<Rows>
</Rows>
</Data>
</ListInstance>
</Elements>

Thursday, 23 February 2012

Personalising DispForm.aspx with JQuery for SharePoint 2010










    The above will give the following






    JQuery and SharePoint

    This works for me...








    Wednesday, 22 February 2012

    Load SharePoint JavaScript Libraries on SharePoint CEWP

    I spent 4 hours wondering why my SharePoint code did not run automatically when I did a _spBodyOnLoadFunctionNames but works when I did an onclick.

    The reason behind this was that the SharePoint javascript Libraries have not been loaded fully when SP. functions were called, thus nothing happened, that is for example SP.ClientContext did not exist yet.



    _spBodyOnLoadFunctionNames.push("LoadLastURL");

    function LoadLastURL()
    {
    var myQueryString = "1";

    var myContext = new SP.ClientContext.get_current();
    ...
    }



    The solution was simple, I just have to do the following





    SP.SOD.executeOrDelayUntilScriptLoaded(LoadLastURL, 'SP.js');


    function LoadLastURL()
    {
    ...sharepoint javascript functions ....
    }

    Friday, 17 February 2012

    Sharepoint 2010: Load parent page to new URL after Item Added

    I was assigned a task for users to be redirected to a page when the new item dialog closes, after figuring things out for 2 days and trawling through google. This is what I came up with.

    The following code will show an Add New Item link, and when the user clicks on the added new URL, he/she will be redirected to that new page in the parent window.




    Add New Item







    Wednesday, 15 February 2012

    Sharepoint 2010: Open New Dialog




    function ShowDialog_Click() {
    var options = {url: "http://somecodesnippets.blogspot.com/",title: "Some Code Snippets",
    allowMaximize: true, showClose: true,
    width: 550,height: 550,
    dialogReturnValueCallback: callBackFunction};
    SP.UI.ModalDialog.showModalDialog(options);
    }

    Visual Studio 2010 Deployment Type 'Missing'

    I was at this issue for half a day when the resolution was so simple!

    I was trying to include an xap file with the module, but deployment type was missing.




    So this was what I did,

    Right click file, and click on Include In Project



    Now deployment type appears!

    Upload to a document library

    I was stuck for hours at uploading files to a document library because i missed out the 'Lists' word in Url="Lists/myControls"!



    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <ListInstance Title="myControls"
    OnQuickLaunch="TRUE"
    TemplateType="101"
    FeatureId="00bfea71-e717-4e80-aa17-d0c71b360101"
    Url="Lists/myControls"
    Description="">
    </ListInstance>
    <Module Name="myControls" Url="Lists/myControls" >
    <File Path="myControls\Text1.txt" Url="Text1.txt" Type="GhostableInLibrary" />
    <File Path="myControls\Text2.txt" Url="Text2.txt" Type="GhostableInLibrary" />
    </Module>
    </Elements>


    Tuesday, 14 February 2012

    Ribbon Tab Behaviour

    Realised that when I use the following CustomAction,


    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction Id="Chapter3.CustomTab" Location="CommandUI.Ribbon" RegistrationType="List" RegistrationId ="101">
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition Location="Ribbon.Tabs._children">
    <Tab Id="Chapter3.CustomTab" Title="Chapter3" Description="Demo tab for Chapter 3" Sequence="501">
    <Scaling Id="Chapter3.CustomTab.Scaling">
    <MaxSize Id="Chapter3.FirstDemoGroup.MaxSize"
    GroupId="Chapter3.FirstDemoGroup"
    Size="OneLarge"/>
    <Scale Id="Chapter3.FirstDemoGroup.Scaling.CustomTabScaling"
    GroupId="Chapter3.FirstDemoGroup"
    Size="OneMedium" />
    </Scaling>
    <Groups Id="Chapter3.Groups">
    <Group Id="Chapter3.FirstDemoGroup"
    Description="Contains demo controls"
    Title="Demo Group"
    Sequence="52"
    Template="Ribbon.Templates.SingleButton">
    <Controls Id="Chapter3.FirstDemoGroup.Controls">
    <Button Id="Chapter3.FirstDemoGroup.HelloWorld"
    Command="Chapter3.HelloWorldCommand"
    Sequence="15"
    Image16by16="/_layouts/images/NoteBoard_16x16.png"
    Image32by32="/_layouts/images/NoteBoard_32x32.png"
    Description="Display a hello world msg"
    LabelText="Hi World"
    TemplateAlias="c1"
    />
    </Controls>
    </Group>
    </Groups>
    </Tab>
    </CommandUIDefinition>
    <CommandUIDefinition Location="Ribbon.Templates._children">
    <GroupTemplate Id="Ribbon.Templates.SingleButton">
    <Layout Title="OneLarge" LayoutTitle="OneLarge">
    <Section Alignment="Top" Type="OneRow">
    <Row>
    <ControlRef DisplayMode="Large" TemplateAlias="c1"/>
    </Row>
    </Section>
    </Layout>
    <Layout Title="OneMedium" LayoutTitle="OneMedium">
    <Section Alignment="Top" Type="OneRow">
    <Row>
    <ControlRef DisplayMode="Medium" TemplateAlias="c1"/>
    </Row>
    </Section>
    </Layout>
    </GroupTemplate>
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <CommandUIHandler Command="Chapter3.HelloWorldCommand"
    CommandAction="javascript:
    var notificationId = SP.UI.Notify.addNotification('Hello World');" />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    </Elements>




    And if you remove the CommandUIHandlers component, the tab will not appear!!!!!!!! Strange...

    Monday, 13 February 2012

    Getting Field name from XSL

    I was trying to do a custom stylesheet that has a field name 'Start Date Time'.
    I was unable to select it from the xsl sheet, after reading http://paulgalvinsoldblog.wordpress.com/2007/12/09/display-content-query-web-part-results-in-a-grid-table/ and listing the fields... it turns out that the field name is NOT

    Start_x0020_Date_x0020_Time

    BUT

    Start_x005F_x0020_Date_x005F_x0020_Time !!!!!!!!!!!!!!!!!!!!

    And I don't understand why when I look at field info within list settings, it shows Start_x0020_Date_x0020_Time !

    Uploading Custom xsl styles to Style Library

    CustomMeetingStyle Module










    Thursday, 9 February 2012

    JQuery with SharePoint

    Did some experimenting with help from
    http://sharepointquicknote.blogspot.com/2011/06/jquery-integration-in-sharepoint.html

    Below shows me how JQuery works by nesting functions within functions, it's like a callback that runs the function within it when it has run..

    Friday, 3 February 2012

    Event Receiver triggered when Publishing Infopath Form

    I had been attempting to publish an Infopath form to a particular List in Sharepoint, and had the error message

    errorinfopath


    After trying to figure out why it was working for other LISTS except that particular named list, even deleted subsites and recreated them to make sure. I finally decided to deactivate the feature that is attached to that LIST.

    Lo and BEHOLD it works!!!!!!!! Now I can publish that infopath form!

    But I really still am puzzled why this is happening....

    Open an edit dialog infopath box from a button in SharePoint

    In the ASPX.CS file

     

    string ListID = cWeb.Lists[listName].ID.ToString();
    ListID = ListID.Replace("-", "%2D");

    btnEdit.Attributes.Add("onclick",
    "OpenDialog('" +
    cWeb.Url +
    "/Lists/myList/Item/editifs.aspx?List=" +
    ListID +
    "&ID=" + listItem.ID +
    "&ContentTypeId=" +
    listItem.ContentTypeId +
    "&IsDlg=1'); return false;");


    In JavaScript, within the ascx file this is added




    //User Defined Function to Open Dialog Framework
    function OpenDialog(strPageURL) {
    OpenCustomDialog(strPageURL, 1050, 500, "Edit");
    return false;
    }


    function OpenCustomDialog(dialogUrl, dialogWidth,
    dialogHeight, dialogTitle,
    dialogAllowMaximize, dialogShowClose) {

    var options =
    {
    url: dialogUrl,
    allowMaximize: dialogAllowMaximize,
    showClose: dialogShowClose,
    width: dialogWidth,
    height: dialogHeight,
    title: dialogTitle,
    dialogReturnValueCallback: function (dialogResult) {
    SP.UI.ModalDialog.RefreshPage(dialogResult)
    }
    }
    SP.UI.ModalDialog.showModalDialog(options);
    }