Tuesday 5 March 2013

Using Modules to Include Files in the Solution

I have seen lots of people struggle with Modules. Sometimes modules are getting deployed successfully but files are not reflecting in Document library.


First of all the Element.xml file should have below structure.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Module Name="MyCustomModule" Url="SitePages" Path="MyCustomModule">
    <File Url="Sample.aspx" Type="GhostableInLibrary"/>
  </Module>
</Elements>

In above XML few things need to be taken care.

Url ( In Module element): Url in module element indicates the URL of the library where files need be created.

Url (In File element) : The location where the file will be deployed on the SharePoint server

Type: It indicates that whether file is available in Document library as a Item. If this attribute is missing, file would be available under list/libraries but it won’t show up in any of the Views.

Tuesday 26 February 2013

Populating current logged in user in people picker

Sometimes there are requirement to populate the current logged in user in People picker field.
I had tried to populate using PickerEntity class, but it use to fail on click of "Check Names" button. So changed the approch to se the comma seprated names and it worked.

1. Take the curent Logged user

loginName = SPContext.Current.Web.CurrentUser.LoginName

2. Assign the login to picker control. 
pkrControlName.CommaSeparatedAccounts =loginName

Note: You can have multiple comma serpated login names to populate multiple users in people picker field.

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...