Posted By

rumremix on 02/10/12


Tagged

project Net Solution sharepoint soln visual-studio


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jlaws0n


Setting up Sharepoint files as a visual studio .Net solution


 / Published in: XML
 

Setting up a sp .net soln

File --> New --> Project

on lefthand side -> Sharepoint -> 2010

usually select an empty template

name the project

to add files, create a module...

right-click project --> add --> new item

select "module"

give the module a name (such as masterpagecatalog)

this will create the module, containing an elements.xml file and open the elements.xml file in code editor. Sample.txt will also be created but may be deleted.

Drag any previously created files that will live in the new module into the module icon in solution explorer

Edit elements.xml. (See example edits to elements.xml in code block further down.)

Edits to make to default xml:

in <Module> tag, put a url (such as Url="_catalogs/masterpage" ) and put RootWebOnly="TRUE"

The <file> tag will also be created with a default url property. Make sure to edit this so that it is correct. By default, it will create a path starting with the name of the module. And if there is no such folder already with that name beneath the Module path, the feature will create one. The actual path is designated by both the <module> url property and the <file> url property (that is, both of those properties are combined).

Add Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" to the <file> elements. IgnoreIfAlreadyExists="TRUE" means "overwrite existing file". Type="GhostableInLibrary" setting is used when a file is placed into a library. If a file is placed outside of a library, Type="Ghostable" would be used.

Change the <file> tags so that it is not self-closing.

Add some Property tags.Columns in the master page correspond to file object properties indicated in the module xml. Other file properties in the xml will also be added to the "property bag" that do not correspond to master page columns (see <property> tags above).

First, it is good practice to always add <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>

On compliation, Value="$SharePoint.Feature.Id$" will be replaced with guid of feature.

For a master page, the following metadata will be added via the property tags

<Property Name="UIVersion" Value="4" />

<Property Name="ContentTypeId" Value="0x010105" />

<Property Name="ContentType" Value="$Resources:cmscore,contenttypemasterpagename;" />

<Property Name="MasterPageDescription" Value="Masterpage for SepulvedaPOC sites." />

Make sure to edit the description as appropriate.

When the module was created, VS automatically created a feature called "Feature 1". Note that features may also be created by right-clicking "Features" in soln explorer and selecting "Add Feature".

Next step: add event reciever feature activated code if necessary

* Make sure to add the proper modules to the feature * Make sure that Scope is set to "Site" in the feature if the solution is a sandbox solution

  1. <!-- ### Example edits to elements.xml ### -->
  2. <!--Here is an example of an edited file for a master page...-->
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  6. <Module Name="masterpagecatalog" Url="_catalogs/masterpage" RootWebOnly="TRUE">
  7. <File Path="masterpagecatalog\LLC.master" Url="LLC.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
  8. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  9. <Property Name="UIVersion" Value="4" />
  10. <Property Name="ContentTypeId" Value="0x010105" />
  11. <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />
  12. <Property Name="MasterPageDescription" Value="Masterpage for Learning Center." />
  13. </File>
  14. </Module>
  15. </Elements>
  16.  
  17. <!--And here is an example of an edited file that places files into three different subfolders within the Style Library...-->
  18.  
  19. <?xml version="1.0" encoding="utf-8"?>
  20. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  21. <Module Name="StyleLibrary" Url="Style Library" RootWebOnly="TRUE">
  22. <File Path="StyleLibrary\lilly_main.css" Url="Lilly/lilly_main.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  23. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  24. </File>
  25. <File Path="StyleLibrary\lessons.js" Url="Scripts/lessons.js" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  26. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  27. </File>
  28. <File Path="StyleLibrary\banner-outlook-rm.jpg" Url="Lilly/images/banner-outlook-rm.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  29. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  30. </File>
  31. <File Path="StyleLibrary\bg-persChoiceBottom.jpg" Url="Lilly/images/bg-persChoiceBottom.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  32. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  33. </File>
  34. <File Path="StyleLibrary\bg-persChoiceMid.jpg" Url="Lilly/images/bg-persChoiceMid.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  35. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  36. </File>
  37. <File Path="StyleLibrary\bg-persChoiceTop.jpg" Url="Lilly/images/bg-persChoiceTop.jpg" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  38. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  39. </File>
  40. <File Path="StyleLibrary\new-window.png" Url="Lilly/images/new-window.png" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
  41. <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
  42. </File>
  43. </Module>
  44.  
  45. </Elements>

Report this snippet  

You need to login to post a comment.